C, properly error on keywords as function parameters

This commit is contained in:
Jakob Lykke Andersen
2020-10-11 13:57:04 +02:00
parent 3f4a58b5b4
commit 17337a3257
3 changed files with 8 additions and 0 deletions

View File

@@ -77,6 +77,8 @@ Bugs fixed
with size explicitly set in pixels) (fixed for ``'pdflatex'/'lualatex'`` only)
* #8911: C++: remove the longest matching prefix in
:confval:`cpp_index_common_prefix` instead of the first that matches.
* C, properly reject function declarations when a keyword is used
as parameter name.
Testing
--------

View File

@@ -2703,6 +2703,9 @@ class DefinitionParser(BaseParser):
declId = None
elif named == 'single':
if self.match(identifier_re):
if self.matched_text in _keywords:
self.fail("Expected identifier, "
"got keyword: %s" % self.matched_text)
identifier = ASTIdentifier(self.matched_text)
declId = ASTNestedName([identifier], rooted=False)
else:

View File

@@ -417,6 +417,9 @@ def test_function_definitions():
check('function', 'void f(int arr[const static volatile 42])', {1: 'f'},
output='void f(int arr[static volatile const 42])')
with pytest.raises(DefinitionError):
parse('function', 'void f(int for)')
def test_nested_name():
check('struct', '{key}.A', {1: "A"})