diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 98b20c1ae1de..eb260e3aa8a4 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -818,7 +818,7 @@ public: const Expr *getAnyInitializer(const VarDecl *&D) const; bool hasInit() const { - return !Init.isNull(); + return !Init.isNull() && (Init.is() || Init.is()); } const Expr *getInit() const { if (Init.isNull()) diff --git a/clang/test/SemaCXX/return-stack-addr.cpp b/clang/test/SemaCXX/return-stack-addr.cpp index 7d4cb964029b..b4d9b9037d54 100644 --- a/clang/test/SemaCXX/return-stack-addr.cpp +++ b/clang/test/SemaCXX/return-stack-addr.cpp @@ -119,5 +119,24 @@ struct PR7999_X {}; PR7999_X& PR7999_f(PR7999 s) { return s.value; } // no-warning void test_PR7999(PR7999_X& x) { (void)PR7999_f(x); } // no-warning +// PR 8774: Don't try to evaluate parameters with default arguments like +// variables with an initializer, especially in templates where the default +// argument may not be an expression (yet). +namespace PR8774 { + template class A { }; + template struct B { }; + template V f(typename B::type const &v = B::value()) { + return v; + } + template <> struct B { + typedef const char *type; + static const char *value(); + }; + void g() { + const char *t; + f(t); + } +} + // TODO: test case for dynamic_cast. clang does not yet have // support for C++ classes to write such a test case.