Author: sepavloff Date: Mon Jun 13 21:55:56 2016 New Revision: 272623 URL: http://llvm.org/viewvc/llvm-project?rev=272623&view=rev Log: 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 Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/default2.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=272623&r1=272622&r2=272623&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 13 21:55:56 2016 @@ -3107,6 +3107,7 @@ def err_use_of_default_argument_to_funct "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 " Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=272623&r1=272622&r2=272623&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jun 13 21:55:56 2016 @@ -4566,6 +4566,13 @@ ExprResult Sema::BuildCXXDefaultArgExpr( } } + // 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. Modified: cfe/trunk/test/SemaCXX/default2.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default2.cpp?rev=272623&r1=272622&r2=272623&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/default2.cpp (original) +++ cfe/trunk/test/SemaCXX/default2.cpp Mon Jun 13 21:55:56 2016 @@ -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}} +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits