From: Douglas Gregor Date: Tue, 13 Jul 2010 06:37:01 +0000 (+0000) Subject: Diagnose typedef of an operator name. Fixes PR7462 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aef01998af5bbfc1cdfac091248ff7d30ec31456;p=clang Diagnose typedef of an operator name. Fixes PR7462 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108233 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index abd11c74d3..c56631b4dc 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -225,6 +225,7 @@ def err_main_arg_wrong : Error<"%select{first|second|third|fourth}0 " /// parser diagnostics def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">; +def err_typedef_not_identifier : Error<"typedef name must be an identifier">; def err_statically_allocated_object : Error< "interface type cannot be statically allocated">; def err_object_cannot_be_passed_returned_by_value : Error< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7d90792376..9c683f726a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2370,6 +2370,12 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (D.getDeclSpec().isThreadSpecified()) Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread); + if (D.getName().Kind != UnqualifiedId::IK_Identifier) { + Diag(D.getName().StartLocation, diag::err_typedef_not_identifier) + << D.getName().getSourceRange(); + return 0; + } + TypedefDecl *NewTD = ParseTypedefDecl(S, D, R, TInfo); if (!NewTD) return 0; diff --git a/test/SemaCXX/typedef-redecl.cpp b/test/SemaCXX/typedef-redecl.cpp index 49e1f3aa79..7db1970a70 100644 --- a/test/SemaCXX/typedef-redecl.cpp +++ b/test/SemaCXX/typedef-redecl.cpp @@ -48,3 +48,9 @@ namespace PR6923 { struct A; } + +namespace PR7462 { + struct A {}; + typedef int operator! (A); // expected-error{{typedef name must be an identifier}} + int i = !A(); // expected-error{{invalid argument type}} +}