diff options
author | Nicolas Lesser <blitzrakete@gmail.com> | 2019-05-04 00:09:00 +0000 |
---|---|---|
committer | Nicolas Lesser <blitzrakete@gmail.com> | 2019-05-04 00:09:00 +0000 |
commit | 6de0b449c07ec7adbcb34e7c94c544ee37ef5963 (patch) | |
tree | 0e2112dbbe57b79622f5a7708add8fecc6a75b80 /test/PCH | |
parent | 6cc60c9164a96f1d73ccfd302303490e0d085b87 (diff) |
[clang] adding explicit(bool) from c++2a
this patch adds support for the explicit bool specifier.
Changes:
- The parsing for the explicit(bool) specifier was added in ParseDecl.cpp.
- The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class.
- Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted.
- Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration.
- The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected.
- Test for Semantic and Serialization were added.
This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback.
Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky.
Patch by Tyker
Differential Revision: https://reviews.llvm.org/D60934
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359949 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/PCH')
-rw-r--r-- | test/PCH/cxx-explicit-specifier.cpp | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/test/PCH/cxx-explicit-specifier.cpp b/test/PCH/cxx-explicit-specifier.cpp new file mode 100644 index 0000000000..a800cfc9d5 --- /dev/null +++ b/test/PCH/cxx-explicit-specifier.cpp @@ -0,0 +1,124 @@ +// RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t-cxx2a +// RUN: %clang_cc1 -std=c++2a -DUSE_PCH -include-pch %t-cxx2a %s -ast-print -verify | FileCheck %s + +#ifndef USE_PCH +namespace inheriting_constructor { + struct S {}; + + template<typename X, typename Y> struct T { + template<typename A> + explicit((Y{}, true)) T(A &&a) {} + }; + + template<typename X, typename Y> struct U : T<X, Y> { + using T<X, Y>::T; + }; + + U<S, char> foo(char ch) { + return U<S, char>(ch); + } +} +#else +namespace inheriting_constructor { +U<S, char> a = foo('0'); +} + +//CHECK: explicit((char{} , true)) + +#endif + +namespace basic { +#ifndef USE_PCH + +struct B {}; + +struct A { + explicit A(int); + explicit(false) operator bool(); + explicit(true) operator B(); +}; +#else +//expected-note@-6+ {{candidate constructor}} +//expected-note@-9+ {{candidate constructor}} +//expected-note@-6+ {{candidate function}} + +//CHECK: explicit{{ +}}A( +//CHECK-NEXT: explicit(false){{ +}}operator +//CHECK-NEXT: explicit(true){{ +}}operator +A a = 0; //expected-error {{no viable conversion}} +A a1(0); + +bool b = a1; +B b1 = a1; //expected-error {{no viable conversion}} + +#endif +} + + +namespace templ { +#ifndef USE_PCH + +template<bool b> +struct B { + static constexpr bool value = b; +}; + +template<bool b> +struct A { + explicit(b) A(B<b>) {} + template<typename T> + explicit(b ^ T::value) operator T(); +}; +B<true> b_true; +B<false> b_false; +#else +//expected-note@-8 {{candidate template ignored}} +//expected-note@-8+ {{explicit constructor}} +//expected-note@-15+ {{candidate constructor}} +//expected-note@-8+ {{candidate conversion operator ignored}} +//expected-note@-9+ {{explicit(bool) specifier resolved to true}} +//expected-note@-12 {{explicit(bool) specifier resolved to true}} +//expected-note@-13+ {{candidate deductiong guide ignored}} + +//CHECK: explicit(b){{ +}}A +//CHECK: explicit(b{{ +}}^{{ +}}T::value){{ +}}operator + +A a = { b_true }; //expected-error {{class template argument deduction}} +A a0 = b_true; //expected-error {{no viable constructor or deduction guide}} +A a_true(b_true); +A a_false = b_false; + +B<true> b = a_true; +B<true> b1 = a_false; //expected-error {{no viable conversion}} +B<false> b2(a_true); + +#endif + +} + +namespace guide { + +#ifndef USE_PCH + +template<typename T> +struct A { + A(T); +}; + +template<typename T> +explicit(true) A(T) -> A<T>; + +explicit(false) A(int) -> A<int>; + +#else +//expected-note@-5 {{explicit deduction guide}} + +//CHECK: explicit(true){{ +}}A( +//CHECK: explicit(false){{ +}}A( + +A a = { 0.0 }; //expected-error {{explicit deduction guide}} +A a1 = { 0 }; + +#endif + +} |