From: Richard Smith Date: Thu, 20 Oct 2011 03:28:47 +0000 (+0000) Subject: Add -Wc++98-compat warning for enumerations in nested name specifiers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=95aafb2453e1fecec8dcfd9e125cd78277f45859;p=clang Add -Wc++98-compat warning for enumerations in nested name specifiers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142568 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 8c70572a74..f2fb998d8a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -833,6 +833,9 @@ def err_incomplete_member_access : Error< "member access into incomplete type %0">; def err_incomplete_type : Error< "incomplete type %0 where a complete type is required">; +def warn_cxx98_compat_enum_nested_name_spec : Warning< + "enumeration type in nested name specifier is incompatible with C++98">, + InGroup, DefaultIgnore; // C++ class members def err_storageclass_invalid_for_member : Error< diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index a9b6536e7d..dfd59bfe4f 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -596,6 +596,9 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier"); } + if (T->isEnumeralType()) + Diag(IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec); + SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T), CCLoc); return false; diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 64315ea15d..03a1d78aa0 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -2629,6 +2629,9 @@ TreeTransform::TransformNestedNameSpecifierLoc( TL.getType()->isEnumeralType())) { assert(!TL.getType().hasLocalQualifiers() && "Can't get cv-qualifiers here"); + if (TL.getType()->isEnumeralType()) + SemaRef.Diag(TL.getBeginLoc(), + diag::warn_cxx98_compat_enum_nested_name_spec); SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, Q.getLocalEndLoc()); break; diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index 6d3abe8537..260e86b0ec 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -237,3 +237,9 @@ namespace UnionOrAnonStructMembers { }; }; } + +int EnumNNS = Enum::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}} +template void EnumNNSFn() { + int k = T::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}} +}; +template void EnumNNSFn(); // expected-note {{in instantiation}}