r221698 - First half of CWG1962: decltype(__func__) should not be a reference type,

Richard Smith richard-llvm at metafoo.co.uk
Tue Nov 11 11:30:42 PST 2014


Author: rsmith
Date: Tue Nov 11 13:30:41 2014
New Revision: 221698

URL: http://llvm.org/viewvc/llvm-project?rev=221698&view=rev
Log:
First half of CWG1962: decltype(__func__) should not be a reference type,
because __func__ is supposed to act like a local static variable.

Added:
    cfe/trunk/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/
    cfe/trunk/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp
Modified:
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=221698&r1=221697&r2=221698&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Nov 11 13:30:41 2014
@@ -5472,6 +5472,8 @@ static QualType getDecltypeForExpr(Sema
   } else if (const ObjCPropertyRefExpr *PR = dyn_cast<ObjCPropertyRefExpr>(E)) {
     if (PR->isExplicitProperty())
       return PR->getExplicitProperty()->getType();
+  } else if (auto *PE = dyn_cast<PredefinedExpr>(E)) {
+    return PE->getType();
   }
   
   // C++11 [expr.lambda.prim]p18:

Added: cfe/trunk/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp?rev=221698&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp (added)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp Tue Nov 11 13:30:41 2014
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++11 %s -verify
+// expected-no-diagnostics
+
+using size_t = decltype(sizeof(0));
+template<typename T> struct check;
+template<size_t N> struct check<const char[N]> {};
+
+constexpr bool startswith(const char *p, const char *q) {
+  return !*q || (*p == *q && startswith(p + 1, q + 1));
+}
+constexpr bool contains(const char *p, const char *q) {
+  return *p && (startswith(p, q) || contains(p + 1, q));
+}
+
+void foo() {
+  check<decltype(__func__)>();
+  static_assert(contains(__func__, "foo"), "");
+}





More information about the cfe-commits mailing list