Skip to content

Commit 90d98a3

Browse files
authored
Revert "[Clang] Added explanation why is_constructible evaluated to false. " (#144127)
Reverts #143309 Someone needs to go through the libc++ tests and update the diagnostics checks in those tests (ie, i don't believe there was anything wrong with the PR, but it impacts libc++ tests nonetheless
1 parent 2f1e6eb commit 90d98a3

File tree

6 files changed

+10
-219
lines changed

6 files changed

+10
-219
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,7 @@ def note_unsatisfied_trait
17671767
: Note<"%0 is not %enum_select<TraitName>{"
17681768
"%TriviallyRelocatable{trivially relocatable}|"
17691769
"%Replaceable{replaceable}|"
1770-
"%TriviallyCopyable{trivially copyable}|"
1771-
"%Constructible{constructible with provided types}"
1770+
"%TriviallyCopyable{trivially copyable}"
17721771
"}1">;
17731772

17741773
def note_unsatisfied_trait_reason
@@ -1798,10 +1797,7 @@ def note_unsatisfied_trait_reason
17981797
"%DeletedAssign{has a deleted %select{copy|move}1 "
17991798
"assignment operator}|"
18001799
"%UnionWithUserDeclaredSMF{is a union with a user-declared "
1801-
"%sub{select_special_member_kind}1}|"
1802-
"%FunctionType{is a function type}|"
1803-
"%CVVoidType{is a cv void type}|"
1804-
"%IncompleteArrayType{is an incomplete array type}"
1800+
"%sub{select_special_member_kind}1}"
18051801
"}0">;
18061802

18071803
def warn_consteval_if_always_true : Warning<

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/AST/DeclCXX.h"
14-
#include "clang/AST/TemplateBase.h"
1514
#include "clang/AST/Type.h"
1615
#include "clang/Basic/DiagnosticParse.h"
1716
#include "clang/Basic/DiagnosticSema.h"
@@ -1948,7 +1947,6 @@ static std::optional<TypeTrait> StdNameToTypeTrait(StringRef Name) {
19481947
TypeTrait::UTT_IsCppTriviallyRelocatable)
19491948
.Case("is_replaceable", TypeTrait::UTT_IsReplaceable)
19501949
.Case("is_trivially_copyable", TypeTrait::UTT_IsTriviallyCopyable)
1951-
.Case("is_constructible", TypeTrait::TT_IsConstructible)
19521950
.Default(std::nullopt);
19531951
}
19541952

@@ -1985,16 +1983,8 @@ static ExtractedTypeTraitInfo ExtractTypeTraitFromExpression(const Expr *E) {
19851983
Trait = StdNameToTypeTrait(Name);
19861984
if (!Trait)
19871985
return std::nullopt;
1988-
for (const auto &Arg : VD->getTemplateArgs().asArray()) {
1989-
if (Arg.getKind() == TemplateArgument::ArgKind::Pack) {
1990-
for (const auto &InnerArg : Arg.pack_elements())
1991-
Args.push_back(InnerArg.getAsType());
1992-
} else if (Arg.getKind() == TemplateArgument::ArgKind::Type) {
1993-
Args.push_back(Arg.getAsType());
1994-
} else {
1995-
llvm_unreachable("Unexpected kind");
1996-
}
1997-
}
1986+
for (const auto &Arg : VD->getTemplateArgs().asArray())
1987+
Args.push_back(Arg.getAsType());
19981988
return {{Trait.value(), std::move(Args)}};
19991989
}
20001990

@@ -2267,60 +2257,6 @@ static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
22672257
}
22682258
}
22692259

2270-
static void DiagnoseNonConstructibleReason(
2271-
Sema &SemaRef, SourceLocation Loc,
2272-
const llvm::SmallVector<clang::QualType, 1> &Ts) {
2273-
if (Ts.empty()) {
2274-
return;
2275-
}
2276-
2277-
bool ContainsVoid = false;
2278-
for (const QualType &ArgTy : Ts) {
2279-
ContainsVoid |= ArgTy->isVoidType();
2280-
}
2281-
2282-
if (ContainsVoid)
2283-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2284-
<< diag::TraitNotSatisfiedReason::CVVoidType;
2285-
2286-
QualType T = Ts[0];
2287-
if (T->isFunctionType())
2288-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2289-
<< diag::TraitNotSatisfiedReason::FunctionType;
2290-
2291-
if (T->isIncompleteArrayType())
2292-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2293-
<< diag::TraitNotSatisfiedReason::IncompleteArrayType;
2294-
2295-
const CXXRecordDecl *D = T->getAsCXXRecordDecl();
2296-
if (!D || D->isInvalidDecl() || !D->hasDefinition())
2297-
return;
2298-
2299-
llvm::BumpPtrAllocator OpaqueExprAllocator;
2300-
SmallVector<Expr *, 2> ArgExprs;
2301-
ArgExprs.reserve(Ts.size() - 1);
2302-
for (unsigned I = 1, N = Ts.size(); I != N; ++I) {
2303-
QualType ArgTy = Ts[I];
2304-
if (ArgTy->isObjectType() || ArgTy->isFunctionType())
2305-
ArgTy = SemaRef.Context.getRValueReferenceType(ArgTy);
2306-
ArgExprs.push_back(
2307-
new (OpaqueExprAllocator.Allocate<OpaqueValueExpr>())
2308-
OpaqueValueExpr(Loc, ArgTy.getNonLValueExprType(SemaRef.Context),
2309-
Expr::getValueKindForType(ArgTy)));
2310-
}
2311-
2312-
EnterExpressionEvaluationContext Unevaluated(
2313-
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
2314-
Sema::ContextRAII TUContext(SemaRef,
2315-
SemaRef.Context.getTranslationUnitDecl());
2316-
InitializedEntity To(InitializedEntity::InitializeTemporary(T));
2317-
InitializationKind InitKind(InitializationKind::CreateDirect(Loc, Loc, Loc));
2318-
InitializationSequence Init(SemaRef, To, InitKind, ArgExprs);
2319-
2320-
Init.Diagnose(SemaRef, To, InitKind, ArgExprs);
2321-
SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
2322-
}
2323-
23242260
static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
23252261
SourceLocation Loc, QualType T) {
23262262
SemaRef.Diag(Loc, diag::note_unsatisfied_trait)
@@ -2360,9 +2296,6 @@ void Sema::DiagnoseTypeTraitDetails(const Expr *E) {
23602296
case UTT_IsTriviallyCopyable:
23612297
DiagnoseNonTriviallyCopyableReason(*this, E->getBeginLoc(), Args[0]);
23622298
break;
2363-
case TT_IsConstructible:
2364-
DiagnoseNonConstructibleReason(*this, E->getBeginLoc(), Args);
2365-
break;
23662299
default:
23672300
break;
23682301
}

clang/test/CXX/drs/cwg18xx.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,11 @@ struct A {
564564
namespace ex2 {
565565
#if __cplusplus >= 201103L
566566
struct Bar {
567-
struct Baz { // #cwg1890-Baz
567+
struct Baz {
568568
int a = 0;
569569
};
570570
static_assert(__is_constructible(Baz), "");
571571
// since-cxx11-error@-1 {{static assertion failed due to requirement '__is_constructible(cwg1890::ex2::Bar::Baz)'}}
572-
// since-cxx11-note@#cwg1890-Baz {{'Baz' defined here}}
573572
};
574573
#endif
575574
} // namespace ex2

clang/test/SemaCXX/overload-resolution-deferred-templates.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,21 @@ struct ImplicitlyCopyable {
8080
static_assert(__is_constructible(ImplicitlyCopyable, const ImplicitlyCopyable&));
8181

8282

83-
struct Movable { // #Movable
83+
struct Movable {
8484
template <typename T>
8585
requires __is_constructible(Movable, T) // #err-self-constraint-1
86-
explicit Movable(T op) noexcept; // #Movable1
87-
Movable(Movable&&) noexcept = default; // #Movable2
86+
explicit Movable(T op) noexcept; // #1
87+
Movable(Movable&&) noexcept = default; // #2
8888
};
8989
static_assert(__is_constructible(Movable, Movable&&));
9090
static_assert(__is_constructible(Movable, const Movable&));
91-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(Movable, const Movable &)'}} \
92-
// expected-error@-1 {{call to implicitly-deleted copy constructor of 'Movable'}} \
93-
// expected-note@#Movable {{'Movable' defined here}} \
94-
// expected-note@#Movable {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const Movable' for 1st argument}} \
95-
// expected-note@#Movable2 {{copy constructor is implicitly deleted because 'Movable' has a user-declared move constructor}} \
96-
// expected-note@#Movable2 {{candidate constructor not viable: no known conversion from 'int' to 'Movable' for 1st argument}} \
97-
// expected-note@#Movable1 {{candidate template ignored: constraints not satisfied [with T = int]}}
98-
91+
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(Movable, const Movable &)'}}
9992

10093
static_assert(__is_constructible(Movable, int));
101-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(Movable, int)'}} \
102-
// expected-error@-1 {{no matching constructor for initialization of 'Movable'}} \
94+
// expected-error@-1{{static assertion failed due to requirement '__is_constructible(Movable, int)'}} \
10395
// expected-note@-1 2{{}}
10496
// expected-error@#err-self-constraint-1{{satisfaction of constraint '__is_constructible(Movable, T)' depends on itself}}
10597
// expected-note@#err-self-constraint-1 4{{}}
106-
// expected-note@#Movable {{'Movable' defined here}}
10798

10899
template <typename T>
109100
struct Members {

clang/test/SemaCXX/type-traits-unsatisfied-diags-std.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ struct is_trivially_copyable {
2020

2121
template <typename T>
2222
constexpr bool is_trivially_copyable_v = __is_trivially_copyable(T);
23-
24-
template <typename... Args>
25-
struct is_constructible {
26-
static constexpr bool value = __is_constructible(Args...);
27-
};
28-
29-
template <typename... Args>
30-
constexpr bool is_constructible_v = __is_constructible(Args...);
3123
#endif
3224

3325
#ifdef STD2
@@ -52,17 +44,6 @@ using is_trivially_copyable = __details_is_trivially_copyable<T>;
5244

5345
template <typename T>
5446
constexpr bool is_trivially_copyable_v = __is_trivially_copyable(T);
55-
56-
template <typename... Args>
57-
struct __details_is_constructible{
58-
static constexpr bool value = __is_constructible(Args...);
59-
};
60-
61-
template <typename... Args>
62-
using is_constructible = __details_is_constructible<Args...>;
63-
64-
template <typename... Args>
65-
constexpr bool is_constructible_v = __is_constructible(Args...);
6647
#endif
6748

6849

@@ -92,15 +73,6 @@ using is_trivially_copyable = __details_is_trivially_copyable<T>;
9273

9374
template <typename T>
9475
constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value;
95-
96-
template <typename... Args>
97-
struct __details_is_constructible : bool_constant<__is_constructible(Args...)> {};
98-
99-
template <typename... Args>
100-
using is_constructible = __details_is_constructible<Args...>;
101-
102-
template <typename... Args>
103-
constexpr bool is_constructible_v = is_constructible<Args...>::value;
10476
#endif
10577

10678
}
@@ -128,15 +100,6 @@ static_assert(std::is_trivially_copyable_v<int&>);
128100
// expected-note@-1 {{because it is a reference type}}
129101

130102

131-
static_assert(std::is_constructible<int, int>::value);
132-
133-
static_assert(std::is_constructible<void>::value);
134-
// expected-error-re@-1 {{static assertion failed due to requirement 'std::{{.*}}is_constructible<void>::value'}} \
135-
// expected-note@-1 {{because it is a cv void type}}
136-
static_assert(std::is_constructible_v<void>);
137-
// expected-error@-1 {{static assertion failed due to requirement 'std::is_constructible_v<void>'}} \
138-
// expected-note@-1 {{because it is a cv void type}}
139-
140103
namespace test_namespace {
141104
using namespace std;
142105
static_assert(is_trivially_relocatable<int&>::value);
@@ -156,13 +119,6 @@ namespace test_namespace {
156119
// expected-error@-1 {{static assertion failed due to requirement 'is_trivially_copyable_v<int &>'}} \
157120
// expected-note@-1 {{'int &' is not trivially copyable}} \
158121
// expected-note@-1 {{because it is a reference type}}
159-
160-
static_assert(is_constructible<void>::value);
161-
// expected-error-re@-1 {{static assertion failed due to requirement '{{.*}}is_constructible<void>::value'}} \
162-
// expected-note@-1 {{because it is a cv void type}}
163-
static_assert(is_constructible_v<void>);
164-
// expected-error@-1 {{static assertion failed due to requirement 'is_constructible_v<void>'}} \
165-
// expected-note@-1 {{because it is a cv void type}}
166122
}
167123

168124

@@ -183,15 +139,6 @@ concept C2 = std::is_trivially_copyable_v<T>; // #concept4
183139

184140
template <C2 T> void g2(); // #cand4
185141

186-
template <typename... Args>
187-
requires std::is_constructible<Args...>::value void f3(); // #cand5
188-
189-
template <typename... Args>
190-
concept C3 = std::is_constructible_v<Args...>; // #concept6
191-
192-
template <C3 T> void g3(); // #cand6
193-
194-
195142
void test() {
196143
f<int&>();
197144
// expected-error@-1 {{no matching function for call to 'f'}} \
@@ -222,19 +169,6 @@ void test() {
222169
// expected-note@#concept4 {{because 'std::is_trivially_copyable_v<int &>' evaluated to false}} \
223170
// expected-note@#concept4 {{'int &' is not trivially copyable}} \
224171
// expected-note@#concept4 {{because it is a reference type}}
225-
226-
f3<void>();
227-
// expected-error@-1 {{no matching function for call to 'f3'}} \
228-
// expected-note@#cand5 {{candidate template ignored: constraints not satisfied [with Args = <void>]}} \
229-
// expected-note-re@#cand5 {{because '{{.*}}is_constructible<void>::value' evaluated to false}} \
230-
// expected-note@#cand5 {{because it is a cv void type}}
231-
232-
g3<void>();
233-
// expected-error@-1 {{no matching function for call to 'g3'}} \
234-
// expected-note@#cand6 {{candidate template ignored: constraints not satisfied [with T = void]}} \
235-
// expected-note@#cand6 {{because 'void' does not satisfy 'C3'}} \
236-
// expected-note@#concept6 {{because 'std::is_constructible_v<void>' evaluated to false}} \
237-
// expected-note@#concept6 {{because it is a cv void type}}
238172
}
239173
}
240174

clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -488,65 +488,3 @@ static_assert(__is_trivially_copyable(S12));
488488
// expected-note@-1 {{'S12' is not trivially copyable}} \
489489
// expected-note@#tc-S12 {{'S12' defined here}}
490490
}
491-
492-
namespace constructible {
493-
494-
struct S1 { // #c-S1
495-
S1(int); // #cc-S1
496-
};
497-
static_assert(__is_constructible(S1, char*));
498-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(constructible::S1, char *)'}} \
499-
// expected-error@-1 {{no matching constructor for initialization of 'S1'}} \
500-
// expected-note@#c-S1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'char *' to 'const S1' for 1st argument}} \
501-
// expected-note@#c-S1 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'char *' to 'S1' for 1st argument}} \
502-
// expected-note@#cc-S1 {{candidate constructor not viable: no known conversion from 'char *' to 'int' for 1st argument; dereference the argument with *}} \
503-
// expected-note@#c-S1 {{'S1' defined here}}
504-
505-
struct S2 { // #c-S2
506-
S2(int, float, double); // #cc-S2
507-
};
508-
static_assert(__is_constructible(S2, float));
509-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(constructible::S2, float)'}} \
510-
// expected-note@#c-S2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'float' to 'const S2' for 1st argument}} \
511-
// expected-note@#c-S2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'float' to 'S2' for 1st argument}} \
512-
// expected-error@-1 {{no matching constructor for initialization of 'S2'}} \
513-
// expected-note@#cc-S2 {{candidate constructor not viable: requires 3 arguments, but 1 was provided}} \
514-
// expected-note@#c-S2 {{'S2' defined here}}
515-
516-
static_assert(__is_constructible(S2, float, void));
517-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(constructible::S2, float, void)'}} \
518-
// expected-note@#c-S2 {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}} \
519-
// expected-note@#c-S2 {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}} \
520-
// expected-note@-1{{because it is a cv void type}} \
521-
// expected-error@-1 {{no matching constructor for initialization of 'S2'}} \
522-
// expected-note@#cc-S2 {{candidate constructor not viable: requires 3 arguments, but 2 were provided}} \
523-
// expected-note@#c-S2 {{'S2' defined here}}
524-
525-
static_assert(__is_constructible(int[]));
526-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(int[])'}} \
527-
// expected-note@-1 {{because it is an incomplete array type}}
528-
529-
static_assert(__is_constructible(void));
530-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void)'}} \
531-
// expected-note@-1 {{because it is a cv void type}}
532-
533-
static_assert(__is_constructible(void, void));
534-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void, void)'}} \
535-
// expected-note@-1 {{because it is a cv void type}}
536-
537-
static_assert(__is_constructible(const void));
538-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(const void)'}} \
539-
// expected-note@-1 {{because it is a cv void type}}
540-
541-
static_assert(__is_constructible(volatile void));
542-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(volatile void)'}} \
543-
// expected-note@-1 {{because it is a cv void type}}
544-
545-
static_assert(__is_constructible(int ()));
546-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(int ())'}} \
547-
// expected-note@-1 {{because it is a function type}}
548-
549-
static_assert(__is_constructible(void (int, float)));
550-
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void (int, float))'}} \
551-
// expected-note@-1 {{because it is a function type}}
552-
}

0 commit comments

Comments
 (0)