[PATCH] D21301: Detect recursive default argument definition

Serge Pavlov via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 13 20:02:43 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL272623: Detect recursive default argument definition (authored by sepavloff).

Changed prior to commit:
  http://reviews.llvm.org/D21301?vs=60564&id=60644#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21301

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaCXX/default2.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3107,6 +3107,7 @@
   "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 "
Index: cfe/trunk/test/SemaCXX/default2.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/default2.cpp
+++ cfe/trunk/test/SemaCXX/default2.cpp
@@ -128,3 +128,7 @@
 
 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}}
+};
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -4566,6 +4566,13 @@
     }
   }
 
+  // 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21301.60644.patch
Type: text/x-patch
Size: 1770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160614/9d5deb5e/attachment.bin>


More information about the cfe-commits mailing list