[PATCH] D66040: [Sema] Implement DR2386 for C++17 structured binding

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 15 12:44:30 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL369043: [Sema] Implement DR2386 for C++17 structured binding (authored by rnk, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66040?vs=215442&id=215456#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66040/new/

https://reviews.llvm.org/D66040

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp
  cfe/trunk/test/CXX/drs/dr23xx.cpp


Index: cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp
===================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp
+++ cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp
@@ -12,7 +12,7 @@
 
 struct Bad1 { int a, b; };
 template<> struct std::tuple_size<Bad1> {};
-void no_tuple_size_3() { auto [x, y] = Bad1(); } // expected-error {{cannot decompose this type; 'std::tuple_size<Bad1>::value' is not a valid integral constant expression}}
+void no_tuple_size_3() { auto [x, y] = Bad1(); } // ok, omitting value is valid after DR2386
 
 struct Bad2 {};
 template<> struct std::tuple_size<Bad2> { const int value = 5; };
Index: cfe/trunk/test/CXX/drs/dr23xx.cpp
===================================================================
--- cfe/trunk/test/CXX/drs/dr23xx.cpp
+++ cfe/trunk/test/CXX/drs/dr23xx.cpp
@@ -40,6 +40,27 @@
 #pragma clang __debug dump not_use_2
 }
 
+#if __cplusplus >= 201707L
+// Otherwise, if the qualified-id std::tuple_size<E> names a complete class
+// type **with a member value**, the expression std::tuple_size<E>::value shall
+// be a well-formed integral constant expression
+namespace dr2386 { // dr2386: 9
+struct Bad1 { int a, b; };
+struct Bad2 { int a, b; };
+} // namespace dr2386
+namespace std {
+template <typename T> struct tuple_size;
+template <> struct std::tuple_size<dr2386::Bad1> {};
+template <> struct std::tuple_size<dr2386::Bad2> {
+  static const int value = 42;
+};
+} // namespace std
+namespace dr2386 {
+void no_value() { auto [x, y] = Bad1(); }
+void wrong_value() { auto [x, y] = Bad2(); } // expected-error {{decomposes into 42 elements}}
+} // namespace dr2386
+#endif
+
 namespace dr2387 { // dr2387: 9
 #if __cplusplus >= 201402L
   template<int> int a = 0;
Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -1030,8 +1030,10 @@
   TemplateArgumentListInfo Args(Loc, Loc);
   Args.addArgument(getTrivialTypeTemplateArgument(S, Loc, T));
 
-  // If there's no tuple_size specialization, it's not tuple-like.
-  if (lookupStdTypeTraitMember(S, R, Loc, "tuple_size", Args, /*DiagID*/0))
+  // If there's no tuple_size specialization or the lookup of 'value' is empty,
+  // it's not tuple-like.
+  if (lookupStdTypeTraitMember(S, R, Loc, "tuple_size", Args, /*DiagID*/ 0) ||
+      R.empty())
     return IsTupleLike::NotTupleLike;
 
   // If we get this far, we've committed to the tuple interpretation, but
@@ -1048,11 +1050,6 @@
     }
   } Diagnoser(R, Args);
 
-  if (R.empty()) {
-    Diagnoser.diagnoseNotICE(S, Loc, SourceRange());
-    return IsTupleLike::Error;
-  }
-
   ExprResult E =
       S.BuildDeclarationNameExpr(CXXScopeSpec(), R, /*NeedsADL*/false);
   if (E.isInvalid())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66040.215456.patch
Type: text/x-patch
Size: 2837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190815/f3aa7f30/attachment.bin>


More information about the cfe-commits mailing list