]> granicus.if.org Git - clang/commitdiff
Add compat/extension warnings for init captures.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Sep 2013 05:38:27 +0000 (05:38 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Sep 2013 05:38:27 +0000 (05:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191609 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaLambda.cpp
test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp
test/CXX/expr/expr.prim/expr.prim.lambda/p8.cpp
test/PCH/cxx11-lambdas.mm
test/Parser/cxx0x-lambda-expressions.cpp
test/Parser/objcxx0x-lambda-expressions.mm
test/SemaCXX/cxx0x-compat.cpp

index 3746252833a93ab6edd1060cdd2b1aae73ae3ccb..2dd7ea7c01d12a25bf2c8f2c0deb5ad96545bbbf 100644 (file)
@@ -5069,6 +5069,11 @@ let CategoryName = "Lambda Issue" in {
     "here">;
 
   // C++1y lambda init-captures.
+  def warn_cxx11_compat_init_capture : Warning<
+    "initialized lambda captures are incompatible with C++ standards "
+    "before C++1y">, InGroup<CXXPre1yCompat>, DefaultIgnore;
+  def ext_init_capture : ExtWarn<
+    "initialized lambda captures are a C++1y extension">, InGroup<CXX1y>;
   def err_init_capture_no_expression : Error<
     "initializer missing for lambda capture %0">;
   def err_init_capture_multiple_expressions : Error<
index a87c903d3bcea40e7028b96e8ef6d1938a97b6c2..fa46a282991c0a45fdbf901eb94497ff5b2a709d 100644 (file)
@@ -703,6 +703,10 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
 
     VarDecl *Var;
     if (C->Init.isUsable()) {
+      Diag(C->Loc, getLangOpts().CPlusPlus1y
+                       ? diag::warn_cxx11_compat_init_capture
+                       : diag::ext_init_capture);
+
       if (C->Init.get()->containsUnexpandedParameterPack())
         ContainsUnexpandedParameterPack = true;
 
index 083ca1bdd377d02c125ce942483794d8f3aa92a6..4ae34dec3e34af84eacbbf9339fea72da9125568 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -Wno-c++1y-extensions
 // RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify
 
 void print();
index 408fb75f8093bb364b34da0602d971f0ac6b39d0..b9b8cd76c011ff1477dd14aa8b5fced443467951 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 %s -verify
+// RUN: %clang_cc1 -std=c++11 %s -verify -Wno-c++1y-extensions
 
 class X0 {
   void explicit_capture() {
index 807bf2306794cf77bbf0083961d819732fbccbb3..c4550517bb1ee312d67c80709bd57f57ad27faa8 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -pedantic-errors -fblocks -std=c++11 -emit-pch %s -o %t-cxx11
-// RUN: %clang_cc1 -ast-print -pedantic-errors -fblocks -std=c++11 -include-pch %t-cxx11  %s | FileCheck -check-prefix=CHECK-PRINT %s
+// RUN: %clang_cc1 -pedantic-errors -fblocks -std=c++1y -emit-pch %s -o %t-cxx11
+// RUN: %clang_cc1 -ast-print -pedantic-errors -fblocks -std=c++1y -include-pch %t-cxx11  %s | FileCheck -check-prefix=CHECK-PRINT %s
 
 #ifndef HEADER_INCLUDED
 
index 426e530251ffaed08332c05d6fc1ce005b555f05..289d03c223b3568f5b6ca2ba62818f045df7f5fe 100644 (file)
@@ -52,14 +52,14 @@ class C {
   // We support init-captures in C++11 as an extension.
   int z;
   void init_capture() {
-    [n(0)] () mutable -> int { return ++n; };
-    [n{0}] { return; }; // expected-error {{<initializer_list>}}
-    [n = 0] { return ++n; }; // expected-error {{captured by copy in a non-mutable}}
-    [n = {0}] { return; }; // expected-error {{<initializer_list>}}
-    [a([&b = z]{})](){};
+    [n(0)] () mutable -> int { return ++n; }; // expected-warning{{extension}}
+    [n{0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}}
+    [n = 0] { return ++n; }; // expected-error {{captured by copy in a non-mutable}} expected-warning{{extension}}
+    [n = {0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}}
+    [a([&b = z]{})](){}; // expected-warning 2{{extension}}
 
     int x = 4;
-    auto y = [&r = x, x = x + 1]() -> int {
+    auto y = [&r = x, x = x + 1]() -> int { // expected-warning 2{{extension}}
       r += 2;
       return x + 2;
     } ();
index 905bd6b1e8b45aa9f5c21a2fad705a73688945ee..bef576a9d20458fb150f5926983af44cd64ea460 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -Wno-c++1y-extensions -std=c++11 %s
 
 class C {
   id get(int);
index 123008aadd81754e38ed908edeb8747eba70e53a..ffbd20fda373d2fce8c962071a36ed3f33bcb7f6 100644 (file)
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++1y -Wc++11-compat -verify %s
+
+#if __cplusplus < 201103L
 
 namespace N {
   template<typename T> void f(T) {} // expected-note 2{{here}}
@@ -37,3 +40,9 @@ void h(size_t foo, size_t bar) {
 
 #define _x + 1
 char c = 'x'_x; // expected-warning {{will be treated as a user-defined literal suffix}}
+
+#else
+
+auto init_capture = [a(0)] {}; // expected-warning {{initialized lambda captures are incompatible with C++ standards before C++1y}}
+
+#endif