Skip to content

Commit 237e175

Browse files
vhscamposkrishna2803
authored andcommitted
Revert "[libc++][Clang] Added explanation why is_constructible evaluated to false. Updated the diagnostics checks in libc++ tests. (llvm#144220)"
This reverts commit e476f96. It has introduced a failure tracked by llvm#150601 One libcxx test fail if libcxx is build with no exceptions and no RTTI: - libcxx/utilities/expected/expected.expected/value.observers.verify.cpp
1 parent 44f0079 commit 237e175

File tree

14 files changed

+13
-239
lines changed

14 files changed

+13
-239
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,10 +1812,7 @@ def note_unsatisfied_trait_reason
18121812
"%DeletedAssign{has a deleted %select{copy|move}1 "
18131813
"assignment operator}|"
18141814
"%UnionWithUserDeclaredSMF{is a union with a user-declared "
1815-
"%sub{select_special_member_kind}1}|"
1816-
"%FunctionType{is a function type}|"
1817-
"%CVVoidType{is a cv void type}|"
1818-
"%IncompleteArrayType{is an incomplete array type}"
1815+
"%sub{select_special_member_kind}1}"
18191816
"}0">;
18201817

18211818
def warn_consteval_if_always_true : Warning<

clang/lib/Sema/SemaTypeTraits.cpp

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

1313
#include "clang/AST/DeclCXX.h"
14-
#include "clang/AST/TemplateBase.h"
1514
#include "clang/AST/Type.h"
16-
#include "clang/Basic/DiagnosticIDs.h"
1715
#include "clang/Basic/DiagnosticParse.h"
1816
#include "clang/Basic/DiagnosticSema.h"
1917
#include "clang/Basic/TypeTraits.h"
@@ -1965,7 +1963,6 @@ static std::optional<TypeTrait> StdNameToTypeTrait(StringRef Name) {
19651963
.Case("is_assignable", TypeTrait::BTT_IsAssignable)
19661964
.Case("is_empty", TypeTrait::UTT_IsEmpty)
19671965
.Case("is_standard_layout", TypeTrait::UTT_IsStandardLayout)
1968-
.Case("is_constructible", TypeTrait::TT_IsConstructible)
19691966
.Default(std::nullopt);
19701967
}
19711968

@@ -2002,16 +1999,8 @@ static ExtractedTypeTraitInfo ExtractTypeTraitFromExpression(const Expr *E) {
20021999
Trait = StdNameToTypeTrait(Name);
20032000
if (!Trait)
20042001
return std::nullopt;
2005-
for (const auto &Arg : VD->getTemplateArgs().asArray()) {
2006-
if (Arg.getKind() == TemplateArgument::ArgKind::Pack) {
2007-
for (const auto &InnerArg : Arg.pack_elements())
2008-
Args.push_back(InnerArg.getAsType());
2009-
} else if (Arg.getKind() == TemplateArgument::ArgKind::Type) {
2010-
Args.push_back(Arg.getAsType());
2011-
} else {
2012-
llvm_unreachable("Unexpected kind");
2013-
}
2014-
}
2002+
for (const auto &Arg : VD->getTemplateArgs().asArray())
2003+
Args.push_back(Arg.getAsType());
20152004
return {{Trait.value(), std::move(Args)}};
20162005
}
20172006

@@ -2284,60 +2273,6 @@ static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
22842273
}
22852274
}
22862275

2287-
static void DiagnoseNonConstructibleReason(
2288-
Sema &SemaRef, SourceLocation Loc,
2289-
const llvm::SmallVector<clang::QualType, 1> &Ts) {
2290-
if (Ts.empty()) {
2291-
return;
2292-
}
2293-
2294-
bool ContainsVoid = false;
2295-
for (const QualType &ArgTy : Ts) {
2296-
ContainsVoid |= ArgTy->isVoidType();
2297-
}
2298-
2299-
if (ContainsVoid)
2300-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2301-
<< diag::TraitNotSatisfiedReason::CVVoidType;
2302-
2303-
QualType T = Ts[0];
2304-
if (T->isFunctionType())
2305-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2306-
<< diag::TraitNotSatisfiedReason::FunctionType;
2307-
2308-
if (T->isIncompleteArrayType())
2309-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2310-
<< diag::TraitNotSatisfiedReason::IncompleteArrayType;
2311-
2312-
const CXXRecordDecl *D = T->getAsCXXRecordDecl();
2313-
if (!D || D->isInvalidDecl() || !D->hasDefinition())
2314-
return;
2315-
2316-
llvm::BumpPtrAllocator OpaqueExprAllocator;
2317-
SmallVector<Expr *, 2> ArgExprs;
2318-
ArgExprs.reserve(Ts.size() - 1);
2319-
for (unsigned I = 1, N = Ts.size(); I != N; ++I) {
2320-
QualType ArgTy = Ts[I];
2321-
if (ArgTy->isObjectType() || ArgTy->isFunctionType())
2322-
ArgTy = SemaRef.Context.getRValueReferenceType(ArgTy);
2323-
ArgExprs.push_back(
2324-
new (OpaqueExprAllocator.Allocate<OpaqueValueExpr>())
2325-
OpaqueValueExpr(Loc, ArgTy.getNonLValueExprType(SemaRef.Context),
2326-
Expr::getValueKindForType(ArgTy)));
2327-
}
2328-
2329-
EnterExpressionEvaluationContext Unevaluated(
2330-
SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
2331-
Sema::ContextRAII TUContext(SemaRef,
2332-
SemaRef.Context.getTranslationUnitDecl());
2333-
InitializedEntity To(InitializedEntity::InitializeTemporary(T));
2334-
InitializationKind InitKind(InitializationKind::CreateDirect(Loc, Loc, Loc));
2335-
InitializationSequence Init(SemaRef, To, InitKind, ArgExprs);
2336-
2337-
Init.Diagnose(SemaRef, To, InitKind, ArgExprs);
2338-
SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
2339-
}
2340-
23412276
static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
23422277
SourceLocation Loc, QualType T) {
23432278
SemaRef.Diag(Loc, diag::note_unsatisfied_trait)
@@ -2624,9 +2559,6 @@ void Sema::DiagnoseTypeTraitDetails(const Expr *E) {
26242559
case UTT_IsStandardLayout:
26252560
DiagnoseNonStandardLayoutReason(*this, E->getBeginLoc(), Args[0]);
26262561
break;
2627-
case TT_IsConstructible:
2628-
DiagnoseNonConstructibleReason(*this, E->getBeginLoc(), Args);
2629-
break;
26302562
default:
26312563
break;
26322564
}

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
@@ -42,14 +42,6 @@ static constexpr bool value = __is_standard_layout(T);
4242
};
4343
template <typename T>
4444
constexpr bool is_standard_layout_v = __is_standard_layout(T);
45-
46-
template <typename... Args>
47-
struct is_constructible {
48-
static constexpr bool value = __is_constructible(Args...);
49-
};
50-
51-
template <typename... Args>
52-
constexpr bool is_constructible_v = __is_constructible(Args...);
5345
#endif
5446

5547
#ifdef STD2
@@ -105,17 +97,6 @@ template <typename T>
10597
using is_standard_layout = __details_is_standard_layout<T>;
10698
template <typename T>
10799
constexpr bool is_standard_layout_v = __is_standard_layout(T);
108-
109-
template <typename... Args>
110-
struct __details_is_constructible{
111-
static constexpr bool value = __is_constructible(Args...);
112-
};
113-
114-
template <typename... Args>
115-
using is_constructible = __details_is_constructible<Args...>;
116-
117-
template <typename... Args>
118-
constexpr bool is_constructible_v = __is_constructible(Args...);
119100
#endif
120101

121102

@@ -168,15 +149,6 @@ template <typename T>
168149
using is_standard_layout = __details_is_standard_layout<T>;
169150
template <typename T>
170151
constexpr bool is_standard_layout_v = is_standard_layout<T>::value;
171-
172-
template <typename... Args>
173-
struct __details_is_constructible : bool_constant<__is_constructible(Args...)> {};
174-
175-
template <typename... Args>
176-
using is_constructible = __details_is_constructible<Args...>;
177-
178-
template <typename... Args>
179-
constexpr bool is_constructible_v = is_constructible<Args...>::value;
180152
#endif
181153

182154
}
@@ -239,15 +211,6 @@ static_assert(std::is_assignable_v<int&, void>);
239211
// expected-error@-1 {{static assertion failed due to requirement 'std::is_assignable_v<int &, void>'}} \
240212
// expected-error@-1 {{assigning to 'int' from incompatible type 'void'}}
241213

242-
static_assert(std::is_constructible<int, int>::value);
243-
244-
static_assert(std::is_constructible<void>::value);
245-
// expected-error-re@-1 {{static assertion failed due to requirement 'std::{{.*}}is_constructible<void>::value'}} \
246-
// expected-note@-1 {{because it is a cv void type}}
247-
static_assert(std::is_constructible_v<void>);
248-
// expected-error@-1 {{static assertion failed due to requirement 'std::is_constructible_v<void>'}} \
249-
// expected-note@-1 {{because it is a cv void type}}
250-
251214
namespace test_namespace {
252215
using namespace std;
253216
static_assert(is_trivially_relocatable<int&>::value);
@@ -293,13 +256,6 @@ namespace test_namespace {
293256
// expected-error@-1 {{static assertion failed due to requirement 'is_empty_v<int &>'}} \
294257
// expected-note@-1 {{'int &' is not empty}} \
295258
// expected-note@-1 {{because it is a reference type}}
296-
297-
static_assert(is_constructible<void>::value);
298-
// expected-error-re@-1 {{static assertion failed due to requirement '{{.*}}is_constructible<void>::value'}} \
299-
// expected-note@-1 {{because it is a cv void type}}
300-
static_assert(is_constructible_v<void>);
301-
// expected-error@-1 {{static assertion failed due to requirement 'is_constructible_v<void>'}} \
302-
// expected-note@-1 {{because it is a cv void type}}
303259
}
304260

305261

@@ -328,15 +284,6 @@ concept C4 = std::is_assignable_v<T, U>; // #concept8
328284

329285
template <C4<void> T> void g4(); // #cand8
330286

331-
template <typename... Args>
332-
requires std::is_constructible<Args...>::value void f3(); // #cand5
333-
334-
template <typename... Args>
335-
concept C3 = std::is_constructible_v<Args...>; // #concept6
336-
337-
template <C3 T> void g3(); // #cand6
338-
339-
340287
void test() {
341288
f<int&>();
342289
// expected-error@-1 {{no matching function for call to 'f'}} \
@@ -380,19 +327,6 @@ void test() {
380327
// expected-note@#cand8 {{because 'C4<int &, void>' evaluated to false}} \
381328
// expected-note@#concept8 {{because 'std::is_assignable_v<int &, void>' evaluated to false}} \
382329
// expected-error@#concept8 {{assigning to 'int' from incompatible type 'void'}}
383-
384-
f3<void>();
385-
// expected-error@-1 {{no matching function for call to 'f3'}} \
386-
// expected-note@#cand5 {{candidate template ignored: constraints not satisfied [with Args = <void>]}} \
387-
// expected-note-re@#cand5 {{because '{{.*}}is_constructible<void>::value' evaluated to false}} \
388-
// expected-note@#cand5 {{because it is a cv void type}}
389-
390-
g3<void>();
391-
// expected-error@-1 {{no matching function for call to 'g3'}} \
392-
// expected-note@#cand6 {{candidate template ignored: constraints not satisfied [with T = void]}} \
393-
// expected-note@#cand6 {{because 'void' does not satisfy 'C3'}} \
394-
// expected-note@#concept6 {{because 'std::is_constructible_v<void>' evaluated to false}} \
395-
// expected-note@#concept6 {{because it is a cv void type}}
396330
}
397331
}
398332

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

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -489,68 +489,6 @@ static_assert(__is_trivially_copyable(S12));
489489
// expected-note@#tc-S12 {{'S12' defined here}}
490490
}
491491

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-
}
553-
554492
namespace assignable {
555493
struct S1;
556494
static_assert(__is_assignable(S1&, const S1&));

libcxx/test/libcxx/utilities/expected/expected.expected/and_then.mandates.verify.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void test() {
5555
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
5656
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
5757
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
58-
// expected-error@*:* 0-1{{excess elements in struct initializer}}
5958
}
6059

6160
// !std::is_same_v<U:error_type, E>
@@ -75,7 +74,6 @@ void test() {
7574
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
7675
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
7776
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
78-
// expected-error@*:* 0-1{{excess elements in struct initializer}}
7977
}
8078

8179
// !std::is_same_v<U:error_type, E>
@@ -96,7 +94,6 @@ void test() {
9694
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
9795
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
9896
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
99-
// expected-error@*:* 0-1{{excess elements in struct initializer}}
10097
}
10198

10299
// !std::is_same_v<U:error_type, E>
@@ -116,7 +113,6 @@ void test() {
116113
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
117114
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
118115
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
119-
// expected-error@*:* 0-1{{excess elements in struct initializer}}
120116
}
121117

122118
// !std::is_same_v<U:error_type, E>

0 commit comments

Comments
 (0)