aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2010-12-13 07:40:47 +0000
committerChandler Carruth <chandlerc@gmail.com>2010-12-13 07:40:47 +0000
commite7f85047d0dd5ebb03d851fab0afa9db07ec2925 (patch)
tree4f504ec2f5c7d16a342152531b37ba6981642675
parent6a57746ea8e94aaf3fbcc961dc95756f5f3dda52 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121692 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Decl.h2
-rw-r--r--test/SemaCXX/return-stack-addr.cpp19
2 files changed, 20 insertions, 1 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 98b20c1ae1..eb260e3aa8 100644
--- a/include/clang/AST/Decl.h
+++ b/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<Stmt *>() || Init.is<EvaluatedStmt *>());
}
const Expr *getInit() const {
if (Init.isNull())
diff --git a/test/SemaCXX/return-stack-addr.cpp b/test/SemaCXX/return-stack-addr.cpp
index 7d4cb96402..b4d9b9037d 100644
--- a/test/SemaCXX/return-stack-addr.cpp
+++ b/test/SemaCXX/return-stack-addr.cpp
@@ -119,5 +119,24 @@ struct PR7999_X {};
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.