[PATCH] D15780: Fix Bug 24863: crasher: "typedef &decltype(auto)::x T; "

Zhang Yuankai via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 25 21:16:17 PST 2015


zhykzhykzhyk created this revision.
zhykzhykzhyk added a reviewer: rsmith.
zhykzhykzhyk added a subscriber: cfe-commits.
zhykzhykzhyk set the repository for this revision to rL LLVM.

Repository:
  rL LLVM

http://reviews.llvm.org/D15780

Files:
  lib/Sema/SemaCXXScopeSpec.cpp
  test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-14.cpp

Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-14.cpp
===================================================================
--- /dev/null
+++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-14.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s -std=c++14
+
+struct S {
+  virtual ~S();
+
+  decltype(auto) a; // expected-error{{'decltype(auto)' not allowed in non-static struct member}}
+  decltype(auto) *b; // expected-error{{'decltype(auto)' not allowed in non-static struct member}}
+
+  void f() throw (decltype(auto)); // expected-error{{'decltype(auto)' not allowed here}}
+
+  friend decltype(auto); // expected-error{{'decltype(auto)' not allowed in non-static struct member}}
+};
+
+// PR 9278: decltype(auto) is not allowed in typedefs, except with a trailing return type.
+typedef decltype(auto) *AutoPtr; // expected-error{{'decltype(auto)' not allowed in typedef}}
+typedef decltype(auto) (*PFun)(int a); // expected-error{{'decltype(auto)' not allowed in typedef}}
+typedef auto Fun(int a) -> decltype(a + a);
+
+void g(decltype(auto) a) { // expected-error{{'decltype(auto)' not allowed in function prototype}}
+  try { }
+  catch (decltype(auto) &a) { } // expected-error{{'decltype(auto)' not allowed in exception declaration}}
+  try { } catch (decltype(auto) a) { } // expected-error{{'decltype(auto)' not allowed in exception declaration}}
+}
+
+void h(decltype(auto) a[10]) { // expected-error{{'decltype(auto)' not allowed in function prototype}}
+}
+
+namespace std {
+  class type_info;
+}
+
+template<typename T> struct U {};
+
+void j() {
+  (void)typeid(decltype(auto)); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)sizeof(decltype(auto)); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)__alignof(decltype(auto)); // expected-error{{'decltype(auto)' not allowed here}}
+
+  U<decltype(auto)> v; // expected-error{{'decltype(auto)' not allowed in template argument}}
+
+  int n;
+  (void)dynamic_cast<decltype(auto)&>(n); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)static_cast<decltype(auto)*>(&n); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)reinterpret_cast<decltype(auto)*>(&n); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)const_cast<decltype(auto)>(n); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)*(decltype(auto)*)(&n); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)decltype(auto)(n); // expected-error{{'decltype(auto)' not allowed here}}
+  (void)decltype(auto){n}; // expected-error{{'decltype(auto)' not allowed here}}
+}
+
+template <decltype(auto) a = 10> class C { }; // expected-error{{'decltype(auto)' not allowed in template parameter}}
+int ints[] = {1, 2, 3};
+enum E : decltype(auto) {}; // expected-error{{'decltype(auto)' not allowed here}}
+struct F : decltype(auto) {}; // expected-error{{'decltype(auto)' not allowed here}}
+template<typename T = decltype(auto)> struct G { }; // expected-error{{'decltype(auto)' not allowed in template argument}}
+
+using A = decltype(auto); // expected-error{{'decltype(auto)' not allowed in type alias}}
+
+typedef &decltype(auto)::x T; // expected-error{{'decltype(auto)' not allowed here}}
Index: lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- lib/Sema/SemaCXXScopeSpec.cpp
+++ lib/Sema/SemaCXXScopeSpec.cpp
@@ -817,6 +817,12 @@
   if (SS.isInvalid() || DS.getTypeSpecType() == DeclSpec::TST_error)
     return true;
 
+  if (DS.getTypeSpecType() == DeclSpec::TST_decltype_auto) {
+    Diag(DS.getTypeSpecTypeLoc(), diag::err_auto_not_allowed)
+      << 1 /* decltype(auto) */ << 15 /* here */;
+    return true;
+  }
+
   assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
 
   QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15780.43637.patch
Type: text/x-patch
Size: 3898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151226/6372c409/attachment.bin>


More information about the cfe-commits mailing list