summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2016-06-14 02:55:56 +0000
committerSerge Pavlov <sepavloff@gmail.com>2016-06-14 02:55:56 +0000
commitb82a9401dfb76131c83f9bb441bf624c1ae7cc7f (patch)
tree57f94c31620c257045a351f953125b3fbda6c52e
parent84685fc8310e89136409a43846dc1018e5a88489 (diff)
downloadbcm5719-llvm-b82a9401dfb76131c83f9bb441bf624c1ae7cc7f.tar.gz
bcm5719-llvm-b82a9401dfb76131c83f9bb441bf624c1ae7cc7f.zip
Detect recursive default argument definition
If definition of default function argument uses itself, clang crashed, because corresponding function parameter is not associated with the default argument yet. With this fix clang emits appropriate error message. This change fixes PR28105. Differential Revision: http://reviews.llvm.org/D21301 llvm-svn: 272623
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td1
-rw-r--r--clang/lib/Sema/SemaExpr.cpp7
-rw-r--r--clang/test/SemaCXX/default2.cpp4
3 files changed, 12 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a607690a14c..9992c779890 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3107,6 +3107,7 @@ def err_use_of_default_argument_to_function_declared_later : Error<
"use of default argument to function %0 that is declared later in class %1">;
def note_default_argument_declared_here : Note<
"default argument declared here">;
+def err_recursive_default_argument : Error<"recursive evaluation of default argument">;
def ext_param_promoted_not_compatible_with_prototype : ExtWarn<
"%diff{promoted type $ of K&R function parameter is not compatible with the "
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f766091e54e..f617db91510 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4566,6 +4566,13 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
}
}
+ // If the default argument expression is not set yet, we are building it now.
+ if (!Param->hasInit()) {
+ Diag(Param->getLocStart(), diag::err_recursive_default_argument) << FD;
+ Param->setInvalidDecl();
+ return ExprError();
+ }
+
// If the default expression creates temporaries, we need to
// push them to the current stack of expression temporaries so they'll
// be properly destroyed.
diff --git a/clang/test/SemaCXX/default2.cpp b/clang/test/SemaCXX/default2.cpp
index c4d40b4280e..8f77f300572 100644
--- a/clang/test/SemaCXX/default2.cpp
+++ b/clang/test/SemaCXX/default2.cpp
@@ -128,3 +128,7 @@ S<1> s;
template <int I1 = I2, int I2 = 1> struct T {}; // expected-error-re {{use of undeclared identifier 'I2'{{$}}}}
T<0, 1> t;
+
+struct PR28105 {
+ PR28105 (int = 0, int = 0, PR28105 = 0); // expected-error{{recursive evaluation of default argument}}
+};
OpenPOWER on IntegriCloud