]> granicus.if.org Git - clang/commitdiff
Move & comment the 'decltype in declarator-id' as suggested by Doug Gregor.
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 14 Dec 2011 18:59:02 +0000 (18:59 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 14 Dec 2011 18:59:02 +0000 (18:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146576 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp

index 63a1b8034e911c1131e773762aad47bc10edda8d..238dbd46792fd9c727d0ba0e910f48d7ce85ef15 100644 (file)
@@ -3203,16 +3203,6 @@ Decl *Sema::HandleDeclarator(Scope *S, Declarator &D,
          (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 @@ Decl *Sema::HandleDeclarator(Scope *S, Declarator &D,
             << 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();
     }
   }
 
index 8dcbaf8381d125c255452f11dc0e2d050c1c46b8..99334b845aba2d986dc7d40c9d0e88adc783a72e 100644 (file)
@@ -18,9 +18,7 @@ class tfoo {
 };
 
 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}}
 }