]> granicus.if.org Git - clang/commitdiff
First half of CWG1962: decltype(__func__) should not be a reference type,
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 11 Nov 2014 19:30:41 +0000 (19:30 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 11 Nov 2014 19:30:41 +0000 (19:30 +0000)
because __func__ is supposed to act like a local static variable.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221698 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp [new file with mode: 0644]

index a6f9483ecdcff976ae1eb4074722481ac582c344..5446f86af0f43b61fdd892a1ca272097aefa9a3f 100644 (file)
@@ -5472,6 +5472,8 @@ static QualType getDecltypeForExpr(Sema &S, Expr *E) {
   } 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:
diff --git a/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp
new file mode 100644 (file)
index 0000000..ff5d3de
--- /dev/null
@@ -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"), "");
+}