]> granicus.if.org Git - clang/commitdiff
Disallow decltype in qualified declarator-ids.
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 13 Dec 2011 08:03:36 +0000 (08:03 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 13 Dec 2011 08:03:36 +0000 (08:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146480 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp [new file with mode: 0644]
test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp

index 56d5348275297d55c0607a7c8fac135be571c6e0..0ad0513d4927cbe038a85af830373c40ea2f4b95 100644 (file)
@@ -1144,6 +1144,8 @@ def err_cannot_determine_declared_type_of_overloaded_function : Error<
 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<
index bd2e639eab0a555497d01a40e5415d5c1307b519..63a1b8034e911c1131e773762aad47bc10edda8d 100644 (file)
@@ -3203,6 +3203,16 @@ 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();
diff --git a/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp b/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
new file mode 100644 (file)
index 0000000..8dcbaf8
--- /dev/null
@@ -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}}
+}
index 80ae67a97c03a5db4665d638dbb5bc2a7d353aca..5b3a004056b52b82994de06fda09e643b0db7cba 100644 (file)
@@ -28,10 +28,6 @@ namespace PR10127 {
              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())'}}