]> granicus.if.org Git - clang/commitdiff
Fix the scope of K&R-style argument declarations so that they don't
authorEli Friedman <eli.friedman@gmail.com>
Tue, 20 May 2008 09:10:20 +0000 (09:10 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 20 May 2008 09:10:20 +0000 (09:10 +0000)
extend beyond the end of the function.

I'm not completely sure this is the right way to fix this bug, so
someone familiar with the parser should double-check.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51311 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/Parser.cpp
test/Parser/traditional_arg_scope.c [new file with mode: 0644]

index 7e41bcc92e339ee8feec481e713bd8b05e7531ef..936604e870b61265d458bf9344284640f6f9e1ec 100644 (file)
@@ -511,7 +511,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
 
   // Enter function-declaration scope, limiting any declarators to the
   // function prototype scope, including parameter declarators.
-  EnterScope(Scope::DeclScope);
+  EnterScope(Scope::FnScope|Scope::DeclScope);
 
   // Read all the argument declarations.
   while (isDeclarationSpecifier()) {
diff --git a/test/Parser/traditional_arg_scope.c b/test/Parser/traditional_arg_scope.c
new file mode 100644 (file)
index 0000000..222de86
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang -fsyntax-only %s -verify
+
+x(a) int a; {return a;}
+y(b) int b; {return a;} // expected-error {{use of undeclared identifier}}
+