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 /unittests | |
parent | 6cc60c9164a96f1d73ccfd302303490e0d085b87 (diff) | |
download | clang-6de0b449c07ec7adbcb34e7c94c544ee37ef5963.tar.gz |
[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 'unittests')
-rw-r--r-- | unittests/AST/Language.cpp | 3 | ||||
-rw-r--r-- | unittests/AST/Language.h | 1 | ||||
-rw-r--r-- | unittests/AST/MatchVerifier.h | 4 | ||||
-rw-r--r-- | unittests/AST/StructuralEquivalenceTest.cpp | 40 |
4 files changed, 48 insertions, 0 deletions
diff --git a/unittests/AST/Language.cpp b/unittests/AST/Language.cpp index 210014b3cd..68b78a3179 100644 --- a/unittests/AST/Language.cpp +++ b/unittests/AST/Language.cpp @@ -34,6 +34,9 @@ ArgVector getBasicRunOptionsForLanguage(Language Lang) { case Lang_CXX14: BasicArgs = {"-std=c++14", "-frtti"}; break; + case Lang_CXX2a: + BasicArgs = {"-std=c++2a", "-frtti"}; + break; case Lang_OpenCL: case Lang_OBJCXX: llvm_unreachable("Not implemented yet!"); diff --git a/unittests/AST/Language.h b/unittests/AST/Language.h index cd19fb7b09..dd61ef8223 100644 --- a/unittests/AST/Language.h +++ b/unittests/AST/Language.h @@ -28,6 +28,7 @@ enum Language { Lang_CXX, Lang_CXX11, Lang_CXX14, + Lang_CXX2a, Lang_OpenCL, Lang_OBJCXX }; diff --git a/unittests/AST/MatchVerifier.h b/unittests/AST/MatchVerifier.h index 1d1bf57db1..7aca7f498e 100644 --- a/unittests/AST/MatchVerifier.h +++ b/unittests/AST/MatchVerifier.h @@ -108,6 +108,10 @@ testing::AssertionResult MatchVerifier<NodeType>::match( Args.push_back("-std=c++14"); FileName = "input.cc"; break; + case Lang_CXX2a: + Args.push_back("-std=c++2a"); + FileName = "input.cc"; + break; case Lang_OpenCL: FileName = "input.cl"; break; diff --git a/unittests/AST/StructuralEquivalenceTest.cpp b/unittests/AST/StructuralEquivalenceTest.cpp index 211b9539cf..5bb4f7e122 100644 --- a/unittests/AST/StructuralEquivalenceTest.cpp +++ b/unittests/AST/StructuralEquivalenceTest.cpp @@ -806,6 +806,26 @@ TEST_F(StructuralEquivalenceTest, CompareSameDeclWithMultiple) { EXPECT_FALSE(testStructuralMatch(t)); } +TEST_F(StructuralEquivalenceTest, ExplicitBoolDifferent) { + auto Decls = makeNamedDecls("struct foo {explicit(false) foo(int);};", + "struct foo {explicit(true) foo(int);};", Lang_CXX2a); + CXXConstructorDecl *First = FirstDeclMatcher<CXXConstructorDecl>().match( + get<0>(Decls), cxxConstructorDecl(hasName("foo"))); + CXXConstructorDecl *Second = FirstDeclMatcher<CXXConstructorDecl>().match( + get<1>(Decls), cxxConstructorDecl(hasName("foo"))); + EXPECT_FALSE(testStructuralMatch(First, Second)); +} + +TEST_F(StructuralEquivalenceTest, ExplicitBoolSame) { + auto Decls = makeNamedDecls("struct foo {explicit(true) foo(int);};", + "struct foo {explicit(true) foo(int);};", Lang_CXX2a); + CXXConstructorDecl *First = FirstDeclMatcher<CXXConstructorDecl>().match( + get<0>(Decls), cxxConstructorDecl(hasName("foo"))); + CXXConstructorDecl *Second = FirstDeclMatcher<CXXConstructorDecl>().match( + get<1>(Decls), cxxConstructorDecl(hasName("foo"))); + EXPECT_TRUE(testStructuralMatch(First, Second)); +} + struct StructuralEquivalenceEnumTest : StructuralEquivalenceTest {}; TEST_F(StructuralEquivalenceEnumTest, FwdDeclEnumShouldBeEqualWithFwdDeclEnum) { @@ -853,5 +873,25 @@ TEST_F(StructuralEquivalenceTemplateTest, DifferentTemplateArgKind) { EXPECT_FALSE(testStructuralMatch(t)); } +TEST_F(StructuralEquivalenceTemplateTest, ExplicitBoolSame) { + auto Decls = makeNamedDecls("template <bool b> struct foo {explicit(b) foo(int);};", + "template <bool b> struct foo {explicit(b) foo(int);};", Lang_CXX2a); + CXXConstructorDecl *First = FirstDeclMatcher<CXXConstructorDecl>().match( + get<0>(Decls), cxxConstructorDecl(hasName("foo<b>"))); + CXXConstructorDecl *Second = FirstDeclMatcher<CXXConstructorDecl>().match( + get<1>(Decls), cxxConstructorDecl(hasName("foo<b>"))); + EXPECT_TRUE(testStructuralMatch(First, Second)); +} + +TEST_F(StructuralEquivalenceTemplateTest, ExplicitBoolDifference) { + auto Decls = makeNamedDecls("template <bool b> struct foo {explicit(b) foo(int);};", + "template <bool b> struct foo {explicit(!b) foo(int);};", Lang_CXX2a); + CXXConstructorDecl *First = FirstDeclMatcher<CXXConstructorDecl>().match( + get<0>(Decls), cxxConstructorDecl(hasName("foo<b>"))); + CXXConstructorDecl *Second = FirstDeclMatcher<CXXConstructorDecl>().match( + get<1>(Decls), cxxConstructorDecl(hasName("foo<b>"))); + EXPECT_FALSE(testStructuralMatch(First, Second)); +} + } // end namespace ast_matchers } // end namespace clang |