From: Douglas Gregor Date: Thu, 13 Sep 2012 20:16:20 +0000 (+0000) Subject: Promote the warning about extra qualification on a declaration from a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75379455fc88ca1f021e55ffe1cab3a9c2b2a37a;p=clang Promote the warning about extra qualification on a declaration from a warning to an error. C++ bans it, and both GCC and EDG diagnose it as an error. Microsoft allows it, so we still warn in Microsoft mode. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163831 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index e85f8359fe..6f813eea3e 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3954,6 +3954,8 @@ def ext_out_of_line_declaration : ExtWarn< "out-of-line declaration of a member must be a definition">, InGroup, DefaultError; def warn_member_extra_qualification : Warning< + "extra qualification on member %0">, InGroup; +def err_member_extra_qualification : Error< "extra qualification on member %0">; def err_member_qualification : Error< "non-friend class member %0 cannot have a qualified name">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 03b33af755..92780d98cd 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3523,7 +3523,8 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, // void X::f(); // }; if (Cur->Equals(DC)) { - Diag(Loc, diag::warn_member_extra_qualification) + Diag(Loc, LangOpts.MicrosoftExt? diag::warn_member_extra_qualification + : diag::err_member_extra_qualification) << Name << FixItHint::CreateRemoval(SS.getRange()); SS.clear(); return false; diff --git a/test/CXX/dcl.decl/dcl.meaning/p1.cpp b/test/CXX/dcl.decl/dcl.meaning/p1.cpp index 3672ea0ea0..ec9a261187 100644 --- a/test/CXX/dcl.decl/dcl.meaning/p1.cpp +++ b/test/CXX/dcl.decl/dcl.meaning/p1.cpp @@ -7,7 +7,7 @@ namespace PR8019 { struct PR8019::x { int x; }; // expected-error{{non-friend class member 'x' cannot have a qualified name}} struct inner; - struct y::inner { }; // expected-warning{{extra qualification on member 'inner'}} + struct y::inner { }; // expected-error{{extra qualification on member 'inner'}} template struct PR8019::x2 { }; // expected-error{{non-friend class member 'x2' cannot have a qualified name}} @@ -16,7 +16,7 @@ namespace PR8019 { struct inner_template; template - struct y::inner_template { }; // expected-warning{{extra qualification on member 'inner_template'}} + struct y::inner_template { }; // expected-error{{extra qualification on member 'inner_template'}} }; } @@ -29,9 +29,9 @@ namespace NS { template void wibble(T); } namespace NS { - void NS::foo() {} // expected-warning{{extra qualification on member 'foo'}} - int NS::bar; // expected-warning{{extra qualification on member 'bar'}} - struct NS::X { }; // expected-warning{{extra qualification on member 'X'}} - template struct NS::Y; // expected-warning{{extra qualification on member 'Y'}} - template void NS::wibble(T) { } // expected-warning{{extra qualification on member 'wibble'}} + void NS::foo() {} // expected-error{{extra qualification on member 'foo'}} + int NS::bar; // expected-error{{extra qualification on member 'bar'}} + struct NS::X { }; // expected-error{{extra qualification on member 'X'}} + template struct NS::Y; // expected-error{{extra qualification on member 'Y'}} + template void NS::wibble(T) { } // expected-error{{extra qualification on member 'wibble'}} } diff --git a/test/CXX/temp/p3.cpp b/test/CXX/temp/p3.cpp index c146bc4faa..11f72de918 100644 --- a/test/CXX/temp/p3.cpp +++ b/test/CXX/temp/p3.cpp @@ -8,7 +8,7 @@ template int S::a, S::b; // expected-error {{can only declare template struct A { static A a; } A::a; // expected-error {{expected ';' after struct}} \ expected-error {{use of undeclared identifier 'T'}} \ - expected-warning{{extra qualification}} + expected-error{{extra qualification}} template struct B { } f(); // expected-error {{expected ';' after struct}} \ expected-error {{requires a type specifier}} diff --git a/test/FixIt/fixit.cpp b/test/FixIt/fixit.cpp index 3eac434a36..dc0b6c8f2a 100644 --- a/test/FixIt/fixit.cpp +++ b/test/FixIt/fixit.cpp @@ -64,7 +64,7 @@ namespace rdar7796492 { // extra qualification on member class C { - int C::foo(); // expected-warning {{extra qualification}} + int C::foo(); // expected-error {{extra qualification}} }; namespace rdar8488464 { diff --git a/test/Misc/warning-flags.c b/test/Misc/warning-flags.c index 5968851d09..a1a0d7ed76 100644 --- a/test/Misc/warning-flags.c +++ b/test/Misc/warning-flags.c @@ -18,7 +18,7 @@ This test serves two purposes: The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (159): +CHECK: Warnings without flags (158): CHECK-NEXT: ext_delete_void_ptr_operand CHECK-NEXT: ext_enum_friend CHECK-NEXT: ext_expected_semi_decl_list @@ -101,7 +101,6 @@ CHECK-NEXT: warn_integer_too_large_for_signed CHECK-NEXT: warn_invalid_asm_cast_lvalue CHECK-NEXT: warn_many_braces_around_scalar_init CHECK-NEXT: warn_maynot_respond -CHECK-NEXT: warn_member_extra_qualification CHECK-NEXT: warn_method_param_redefinition CHECK-NEXT: warn_mismatched_exception_spec CHECK-NEXT: warn_missing_case_for_condition diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index 0b72cd3e1f..9b50d3d28b 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -203,3 +203,4 @@ struct PR11150 { void f() { int __except = 0; } +void ::f(); // expected-warning{{extra qualification on member 'f'}} diff --git a/test/SemaCXX/class.cpp b/test/SemaCXX/class.cpp index 4dffc8d9ec..972a79bb60 100644 --- a/test/SemaCXX/class.cpp +++ b/test/SemaCXX/class.cpp @@ -120,7 +120,7 @@ struct C4 { struct S { void f(); // expected-note 1 {{previous declaration}} - void S::f() {} // expected-warning {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}} + void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}} void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}} }; diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index b35e382286..7239646d8d 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -159,7 +159,7 @@ namespace N { void f(); // FIXME: if we move this to a separate definition of N, things break! } -void ::global_func2(int) { } // expected-warning{{extra qualification on member 'global_func2'}} +void ::global_func2(int) { } // expected-error{{extra qualification on member 'global_func2'}} void N::f() { } // okay @@ -245,15 +245,15 @@ namespace PR7133 { } class CLASS { - void CLASS::foo2(); // expected-warning {{extra qualification on member 'foo2'}} + void CLASS::foo2(); // expected-error {{extra qualification on member 'foo2'}} }; namespace PR8159 { class B { }; class A { - int A::a; // expected-warning{{extra qualification on member 'a'}} - static int A::b; // expected-warning{{extra qualification on member 'b'}} + int A::a; // expected-error{{extra qualification on member 'a'}} + static int A::b; // expected-error{{extra qualification on member 'b'}} int ::c; // expected-error{{non-friend class member 'c' cannot have a qualified name}} }; }