[cfe-commits] r118138 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/PR8012.cpp

Sean Hunt scshunt at csclub.uwaterloo.ca
Tue Nov 2 18:07:06 PDT 2010


Author: coppro
Date: Tue Nov  2 20:07:06 2010
New Revision: 118138

URL: http://llvm.org/viewvc/llvm-project?rev=118138&view=rev
Log:
Provide an error when a non-identifier name (such as an operator) is used as a
parameter name.

Fixes PR8012.

Added:
    cfe/trunk/test/SemaCXX/PR8012.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=118138&r1=118137&r2=118138&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Nov  2 20:07:06 2010
@@ -95,6 +95,8 @@
   "type specifier required for unnamed parameter, defaults to int">;
 def err_bad_variable_name : Error<
   "'%0' cannot be the name of a variable or data member">;
+def err_bad_parameter_name : Error<
+  "'%0' cannot be the name of a parameter">;
 def err_parameter_name_omitted : Error<"parameter name omitted">;
 def warn_unused_parameter : Warning<"unused parameter %0">,
   InGroup<UnusedParameter>, DefaultIgnore;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=118138&r1=118137&r2=118138&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov  2 20:07:06 2010
@@ -4757,8 +4757,18 @@
       << Context.getTypeDeclType(OwnedDecl);
   }
 
+  // Ensure we have a valid name
+  IdentifierInfo *II = 0;
+  if (D.hasName()) {
+    II = D.getIdentifier();
+    if (!II) {
+      Diag(D.getIdentifierLoc(), diag::err_bad_parameter_name)
+        << GetNameForDeclarator(D).getName().getAsString();
+      D.setInvalidType(true);
+    }
+  }
+
   // Check for redeclaration of parameters, e.g. int foo(int x, int x);
-  IdentifierInfo *II = D.getIdentifier();
   if (II) {
     LookupResult R(*this, II, D.getIdentifierLoc(), LookupOrdinaryName,
                    ForRedeclaration);

Added: cfe/trunk/test/SemaCXX/PR8012.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR8012.cpp?rev=118138&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR8012.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR8012.cpp Tue Nov  2 20:07:06 2010
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x
+
+void foo (int operator+); // expected-error{{cannot be the name of a parameter}}





More information about the cfe-commits mailing list