From: Richard Smith Date: Tue, 11 Nov 2014 19:30:41 +0000 (+0000) Subject: First half of CWG1962: decltype(__func__) should not be a reference type, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d53e9cfbcf57d0a29475da315655e3c6e53f4a2;p=clang First half of CWG1962: decltype(__func__) should not be a reference type, 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 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index a6f9483ecd..5446f86af0 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -5472,6 +5472,8 @@ static QualType getDecltypeForExpr(Sema &S, Expr *E) { } else if (const ObjCPropertyRefExpr *PR = dyn_cast(E)) { if (PR->isExplicitProperty()) return PR->getExplicitProperty()->getType(); + } else if (auto *PE = dyn_cast(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 index 0000000000..ff5d3dec30 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++11 %s -verify +// expected-no-diagnostics + +using size_t = decltype(sizeof(0)); +template struct check; +template struct check {}; + +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(); + static_assert(contains(__func__, "foo"), ""); +}