[cfe-commits] r121692 - in /cfe/trunk: include/clang/AST/Decl.h test/SemaCXX/return-stack-addr.cpp
Chandler Carruth
chandlerc at gmail.com
Sun Dec 12 23:40:47 PST 2010
Author: chandlerc
Date: Mon Dec 13 01:40:47 2010
New Revision: 121692
URL: http://llvm.org/viewvc/llvm-project?rev=121692&view=rev
Log:
Fix PR8774 by restricting when hasInit returns true. Previously, it
would return true if the initializer pointer union had *any* non-null
pointer in it, even if the pointer wasn't one that would actually be
returned via getInit(). This makes it more accurately model the logic of
'getInit() != NULL'.
This still isn't completely satisfying. From a principled stance,
I suspect we should make hasInit() and getInit() *always* return false
and NULL (resp.) for ParmVarDecl. We shouldn't at the API level treat
initializers and default arguments as the same thing.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/test/SemaCXX/return-stack-addr.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=121692&r1=121691&r2=121692&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Dec 13 01:40:47 2010
@@ -818,7 +818,7 @@
const Expr *getAnyInitializer(const VarDecl *&D) const;
bool hasInit() const {
- return !Init.isNull();
+ return !Init.isNull() && (Init.is<Stmt *>() || Init.is<EvaluatedStmt *>());
}
const Expr *getInit() const {
if (Init.isNull())
Modified: cfe/trunk/test/SemaCXX/return-stack-addr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return-stack-addr.cpp?rev=121692&r1=121691&r2=121692&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/return-stack-addr.cpp (original)
+++ cfe/trunk/test/SemaCXX/return-stack-addr.cpp Mon Dec 13 01:40:47 2010
@@ -119,5 +119,24 @@
PR7999_X& PR7999_f(PR7999<PR7999_X> 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 <typename T> class A { };
+ template <typename U> struct B { };
+ template <typename V> V f(typename B<V>::type const &v = B<V>::value()) {
+ return v;
+ }
+ template <> struct B<const char *> {
+ typedef const char *type;
+ static const char *value();
+ };
+ void g() {
+ const char *t;
+ f<const char*>(t);
+ }
+}
+
// TODO: test case for dynamic_cast. clang does not yet have
// support for C++ classes to write such a test case.
More information about the cfe-commits
mailing list