[clang] aa76935 - [c++20] Consistent with the intent to allow all plausible types in

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 20 23:09:37 PDT 2020


Author: Richard Smith
Date: 2020-09-20T23:09:26-07:00
New Revision: aa769358d8c80d06963d7bc529dd6edd76d3f0de

URL: https://github.com/llvm/llvm-project/commit/aa769358d8c80d06963d7bc529dd6edd76d3f0de
DIFF: https://github.com/llvm/llvm-project/commit/aa769358d8c80d06963d7bc529dd6edd76d3f0de.diff

LOG: [c++20] Consistent with the intent to allow all plausible types in
non-type template parameters, permit vector types.

Added: 
    

Modified: 
    clang/lib/AST/DeclCXX.cpp
    clang/lib/AST/Type.cpp
    clang/test/CXX/temp/temp.param/p7.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 88ca7cf11606..84a0be5ee199 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1345,7 +1345,7 @@ void CXXRecordDecl::addedMember(Decl *D) {
       //   types of all non-static data members are structural types or
       //   (possibly multidimensional) array thereof
       // We deal with class types elsewhere.
-      if (!T->isScalarType() && !T->isLValueReferenceType())
+      if (!T->isStructuralType())
         data().StructuralIfLiteral = false;
     }
 

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 8a47b75ac88a..1e31ba76cca4 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2600,7 +2600,8 @@ bool Type::isStructuralType() const {
   // C++20 [temp.param]p6:
   //   A structural type is one of the following:
   //   -- a scalar type; or
-  if (isScalarType())
+  //   -- a vector type [Clang extension]; or
+  if (isScalarType() || isVectorType())
     return true;
   //   -- an lvalue reference type; or
   if (isLValueReferenceType())

diff  --git a/clang/test/CXX/temp/temp.param/p7.cpp b/clang/test/CXX/temp/temp.param/p7.cpp
index bc203a8ad2ff..ae78af7a016c 100644
--- a/clang/test/CXX/temp/temp.param/p7.cpp
+++ b/clang/test/CXX/temp/temp.param/p7.cpp
@@ -32,15 +32,15 @@ template<_Complex float ci> struct ComplexFloat; // cxx17-error {{cannot have ty
 template<_Complex int ci> struct ComplexInt; // cxx17-error {{cannot have type '_Complex int' before C++20}}
 template<_ExtInt(42) ei> struct ExtInt;
 
-// atomic and vector types aren't scalar types
-// FIXME: Consider permitting vector types here.
+// atomic types aren't scalar types
 template<_Atomic float ci> struct AtomicFloat; // expected-error {{cannot have type '_Atomic(float)'}}
 template<_Atomic int ci> struct AtomicInt; // expected-error {{cannot have type '_Atomic(int)'}}
 
+// we allow vector types as an extension
 typedef __attribute__((ext_vector_type(4))) int VI4;
 typedef __attribute__((ext_vector_type(4))) float VF4;
-template<VI4> struct VectorInt; // expected-error {{cannot have type 'VI4'}}
-template<VF4> struct VectorFloat; // expected-error {{cannot have type 'VF4'}}
+template<VI4> struct VectorInt; // cxx17-error {{cannot have type 'VI4'}}
+template<VF4> struct VectorFloat; // cxx17-error {{cannot have type 'VF4'}}
 
 struct A2 {};
 
@@ -64,6 +64,8 @@ struct B : A, public A2 {
   _Complex int ci;
   _Complex float cf;
   _ExtInt(42) ei;
+  VI4 vi4;
+  VF4 vf4;
 };
 
 template<B> struct ClassNTTP {}; // cxx17-error {{cannot have type 'B'}}
@@ -119,8 +121,6 @@ struct MutableField {
 };
 template<MutableField> struct WithMutableField {}; // cxx17-error {{cannot have type}} cxx20-error {{is not a structural type}}
 
-template<typename T> struct BadExtType { T t; }; // cxx20-note 4{{has a non-static data member of non-structural type}}
+template<typename T> struct BadExtType { T t; }; // cxx20-note 2{{has a non-static data member of non-structural type}}
 template<BadExtType<_Atomic float> > struct AtomicFloatField; // cxx17-error {{cannot have type}} cxx20-error {{is not a structural type}}
 template<BadExtType<_Atomic int> > struct AtomicInt; // cxx17-error {{cannot have type}} cxx20-error {{is not a structural type}}
-template<BadExtType<VI4> > struct VectorInt; // cxx17-error {{cannot have type}} cxx20-error {{is not a structural type}}
-template<BadExtType<VF4> > struct VectorFloat; // cxx17-error {{cannot have type}} cxx20-error {{is not a structural type}}


        


More information about the cfe-commits mailing list