[cfe-commits] r146480 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp

David Blaikie dblaikie at gmail.com
Tue Dec 13 00:03:36 PST 2011


Author: dblaikie
Date: Tue Dec 13 02:03:36 2011
New Revision: 146480

URL: http://llvm.org/viewvc/llvm-project?rev=146480&view=rev
Log:
Disallow decltype in qualified declarator-ids.

Added:
    cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=146480&r1=146479&r2=146480&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 13 02:03:36 2011
@@ -1144,6 +1144,8 @@
 def warn_cxx98_compat_decltype : Warning<
   "'decltype' type specifier is incompatible with C++98">,
   InGroup<CXX98Compat>, DefaultIgnore;
+def err_decltype_in_declarator : Error<
+    "'decltype' cannot be used to name a declaration">;
     
 // C++11 auto
 def warn_cxx98_compat_auto_type_specifier : Warning<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=146480&r1=146479&r2=146480&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 13 02:03:36 2011
@@ -3203,6 +3203,16 @@
          (S->getFlags() & Scope::TemplateParamScope) != 0)
     S = S->getParent();
 
+  if (NestedNameSpecifierLoc SpecLoc = 
+        D.getCXXScopeSpec().getWithLocInContext(Context)) {
+    while (SpecLoc.getPrefix())
+      SpecLoc = SpecLoc.getPrefix();
+    if (dyn_cast_or_null<DecltypeType>(
+          SpecLoc.getNestedNameSpecifier()->getAsType()))
+      Diag(SpecLoc.getBeginLoc(), diag::err_decltype_in_declarator)
+        << SpecLoc.getTypeLoc().getSourceRange();
+  }
+
   DeclContext *DC = CurContext;
   if (D.getCXXScopeSpec().isInvalid())
     D.setInvalidType();

Added: cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp?rev=146480&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp (added)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp Tue Dec 13 02:03:36 2011
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+// The nested-name-specifier of a qualified declarator-id shall not begin with a decltype-specifier.
+class foo {
+  static int i;
+  void func();
+};
+
+int decltype(foo())::i; // expected-error{{'decltype' cannot be used to name a declaration}}
+void decltype(foo())::func() { // expected-error{{'decltype' cannot be used to name a declaration}}
+}
+
+
+template<typename T>
+class tfoo {
+  static int i;
+  void func();
+};
+
+template<typename T>
+int decltype(tfoo<T>())::i; // expected-error{{'decltype' cannot be used to name a declaration}} \
+                               expected-error{{nested name specifier 'decltype(tfoo<T>())::' for declaration does not refer into a class, class template or class template partial specialization}}
+template<typename T>
+void decltype(tfoo<T>())::func() { // expected-error{{'decltype' cannot be used to name a declaration}} \
+                               expected-error{{nested name specifier 'decltype(tfoo<T>())::' for declaration does not refer into a class, class template or class template partial specialization}}
+}

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp?rev=146480&r1=146479&r2=146480&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp Tue Dec 13 02:03:36 2011
@@ -28,10 +28,6 @@
              int (decltype(outer())::middle::inner::*p)());
   };
 
-  int decltype(outer::middle())::inner::func() {
-    return 0;
-  }
-
   decltype(outer::middle::inner()) a;
   void scope() {
     a.decltype(outer::middle())::mfunc(); // expected-error{{'PR10127::outer::middle::mfunc' is not a member of class 'decltype(outer::middle::inner())'}}





More information about the cfe-commits mailing list