[cfe-commits] r141513 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp test/SemaCXX/overloaded-operator-decl.cpp
Douglas Gregor
dgregor at apple.com
Sun Oct 9 11:55:59 PDT 2011
Author: dgregor
Date: Sun Oct 9 13:55:59 2011
New Revision: 141513
URL: http://llvm.org/viewvc/llvm-project?rev=141513&view=rev
Log:
Diagnose attempts to declare a non-static data member with a
non-identifier name. Fixes PR10839.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=141513&r1=141512&r2=141513&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Oct 9 13:55:59 2011
@@ -103,7 +103,7 @@
def ext_anon_param_requires_type_specifier : Extension<
"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">;
+ "%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">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=141513&r1=141512&r2=141513&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 9 13:55:59 2011
@@ -3720,7 +3720,7 @@
IdentifierInfo *II = Name.getAsIdentifierInfo();
if (!II) {
Diag(D.getIdentifierLoc(), diag::err_bad_variable_name)
- << Name.getAsString();
+ << Name;
return 0;
}
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=141513&r1=141512&r2=141513&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Oct 9 13:55:59 2011
@@ -1487,8 +1487,14 @@
Decl *Member;
if (isInstField) {
CXXScopeSpec &SS = D.getCXXScopeSpec();
+
+ // Data members must have identifiers for names.
+ if (Name.getNameKind() != DeclarationName::Identifier) {
+ Diag(Loc, diag::err_bad_variable_name)
+ << Name;
+ return 0;
+ }
- // FIXME: Check that the name is an identifier!
IdentifierInfo *II = Name.getAsIdentifierInfo();
// Member field could not be with "template" keyword.
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp?rev=141513&r1=141512&r2=141513&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp Sun Oct 9 13:55:59 2011
@@ -7,8 +7,9 @@
class K {
virtual ~K();
- // FIXME: the diagnostic here is really bad
- operator struct S {} (); // expected-error 2{{}} expected-note {{}}
+ // FIXME: Diagnostic could use some work
+ operator struct S {} (); // expected-error{{ 'operator S' cannot be the name of a variable or data member}} \
+ // expected-error{{expected ';' at end of declaration list}}
};
void f() {
Modified: cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp?rev=141513&r1=141512&r2=141513&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp (original)
+++ cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp Sun Oct 9 13:55:59 2011
@@ -43,3 +43,8 @@
void operator()();
} plus;
}
+
+struct PR10839 {
+ operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
+ int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
+};
More information about the cfe-commits
mailing list