[cfe-commits] r146576 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp

David Blaikie dblaikie at gmail.com
Wed Dec 14 10:59:02 PST 2011


Author: dblaikie
Date: Wed Dec 14 12:59:02 2011
New Revision: 146576

URL: http://llvm.org/viewvc/llvm-project?rev=146576&view=rev
Log:
Move & comment the 'decltype in declarator-id' as suggested by Doug Gregor.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=146576&r1=146575&r2=146576&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Dec 14 12:59:02 2011
@@ -3203,16 +3203,6 @@
          (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();
@@ -3377,6 +3367,20 @@
             << Name << cast<NamedDecl>(DC) << R;
         D.setInvalidType();
       }
+
+      // C++11 8.3p1:
+      // ... "The nested-name-specifier of the qualified declarator-id shall
+      // not begin with a decltype-specifer"
+      NestedNameSpecifierLoc SpecLoc = 
+            D.getCXXScopeSpec().getWithLocInContext(Context);
+      assert(SpecLoc && "A non-empty CXXScopeSpec should have a non-empty "
+                        "NestedNameSpecifierLoc");
+      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();
     }
   }
 

Modified: 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=146576&r1=146575&r2=146576&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp Wed Dec 14 12:59:02 2011
@@ -18,9 +18,7 @@
 };
 
 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}}
+int decltype(tfoo<T>())::i; // 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}}
+void decltype(tfoo<T>())::func() { // expected-error{{nested name specifier 'decltype(tfoo<T>())::' for declaration does not refer into a class, class template or class template partial specialization}}
 }





More information about the cfe-commits mailing list