mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Make c++17 deduction guides unconditionally enabled
This commit is contained in:
parent
7d1ea08ae0
commit
a1c904fbc7
7 changed files with 16 additions and 68 deletions
|
@ -112,12 +112,6 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
STDCPP17 {
|
|
||||||
@Override
|
|
||||||
public boolean isUseGNUExtensions() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
STDCPP20 {
|
STDCPP20 {
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseGNUExtensions() {
|
public boolean isUseGNUExtensions() {
|
||||||
|
@ -134,7 +128,6 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
|
|
||||||
private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap());
|
private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap());
|
||||||
private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap());
|
private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap());
|
||||||
private static final ScannerInfo STDCPP17_SCANNER_INFO = new ScannerInfo(getStdCpp17Map());
|
|
||||||
private static final ScannerInfo STDCPP20_SCANNER_INFO = new ScannerInfo(getStdCpp20Map());
|
private static final ScannerInfo STDCPP20_SCANNER_INFO = new ScannerInfo(getStdCpp20Map());
|
||||||
|
|
||||||
private static Map<String, String> getGnuMap() {
|
private static Map<String, String> getGnuMap() {
|
||||||
|
@ -161,18 +154,10 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, String> getStdCpp17Map() {
|
|
||||||
Map<String, String> map = getStdMap();
|
|
||||||
map.put("__cpp_deduction_guides", "201703L");
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, String> getStdCpp20Map() {
|
private static Map<String, String> getStdCpp20Map() {
|
||||||
Map<String, String> map = getStdCpp17Map();
|
Map<String, String> map = getStdMap();
|
||||||
map.put("__cpp_impl_three_way_comparison", "201907L");
|
map.put("__cpp_impl_three_way_comparison", "201907L");
|
||||||
map.put("__cpp_char8_t", "201811L");
|
map.put("__cpp_char8_t", "201811L");
|
||||||
// TODO: C++20 features
|
|
||||||
//map.put("__cpp_deduction_guides", "201907L");
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,8 +241,6 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
switch (scannerKind) {
|
switch (scannerKind) {
|
||||||
case GNU:
|
case GNU:
|
||||||
return GNU_SCANNER_INFO;
|
return GNU_SCANNER_INFO;
|
||||||
case STDCPP17:
|
|
||||||
return STDCPP17_SCANNER_INFO;
|
|
||||||
case STDCPP20:
|
case STDCPP20:
|
||||||
return STDCPP20_SCANNER_INFO;
|
return STDCPP20_SCANNER_INFO;
|
||||||
case STD:
|
case STD:
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
|
||||||
// S convert(ddouble);
|
// S convert(ddouble);
|
||||||
// }
|
// }
|
||||||
public void testDeductionGuideBasic() throws Exception {
|
public void testDeductionGuideBasic() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STDCPP17);
|
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STD);
|
||||||
assertType(bh.assertNonProblem("dchar = S", 5), char_);
|
assertType(bh.assertNonProblem("dchar = S", 5), char_);
|
||||||
assertType(bh.assertNonProblem("dint = S", 4), double_);
|
assertType(bh.assertNonProblem("dint = S", 4), double_);
|
||||||
assertType(bh.assertNonProblem("dv = S", 2), double_);
|
assertType(bh.assertNonProblem("dv = S", 2), double_);
|
||||||
|
@ -85,7 +85,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
|
||||||
// int iv = S(1).value;
|
// int iv = S(1).value;
|
||||||
// }
|
// }
|
||||||
public void testDeductionGuideWithDefaultTemplateArg() throws Exception {
|
public void testDeductionGuideWithDefaultTemplateArg() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STDCPP17);
|
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STD);
|
||||||
assertType(bh.assertNonProblem("dchar = S", 5), char_);
|
assertType(bh.assertNonProblem("dchar = S", 5), char_);
|
||||||
assertType(bh.assertNonProblem("dint = S", 4), double_);
|
assertType(bh.assertNonProblem("dint = S", 4), double_);
|
||||||
assertType(bh.assertNonProblem("dv = S", 2), double_);
|
assertType(bh.assertNonProblem("dv = S", 2), double_);
|
||||||
|
@ -107,7 +107,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
|
||||||
// S convert(ddouble);
|
// S convert(ddouble);
|
||||||
// }
|
// }
|
||||||
public void testDeductionGuideWithTemplateDeclaration() throws Exception {
|
public void testDeductionGuideWithTemplateDeclaration() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STDCPP17);
|
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STD);
|
||||||
|
|
||||||
IVariable varChar = bh.assertNonProblem("schar = S", 5);
|
IVariable varChar = bh.assertNonProblem("schar = S", 5);
|
||||||
assertType(bh.assertNonProblem("dchar = S", 5), varChar.getType());
|
assertType(bh.assertNonProblem("dchar = S", 5), varChar.getType());
|
||||||
|
@ -131,7 +131,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
|
||||||
// UniquePtr dp{new auto(2.0)};
|
// UniquePtr dp{new auto(2.0)};
|
||||||
// auto da = dp;
|
// auto da = dp;
|
||||||
public void testMinimal() throws Exception {
|
public void testMinimal() throws Exception {
|
||||||
parseAndCheckBindings(ScannerKind.STDCPP17);
|
parseAndCheckBindings(ScannerKind.STD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// template<class T> struct S {
|
// template<class T> struct S {
|
||||||
|
@ -146,7 +146,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
|
||||||
//
|
//
|
||||||
// S s2;
|
// S s2;
|
||||||
public void testDeduceFromEmptyInitializer() throws Exception {
|
public void testDeduceFromEmptyInitializer() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STDCPP17);
|
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STD);
|
||||||
IVariable varSInt = bh.assertNonProblem("sInt", 4);
|
IVariable varSInt = bh.assertNonProblem("sInt", 4);
|
||||||
bh.assertProblem("S s1", 1);
|
bh.assertProblem("S s1", 1);
|
||||||
bh.assertNonProblem("S s2", 1);
|
bh.assertNonProblem("S s2", 1);
|
||||||
|
@ -165,14 +165,14 @@ public class DeductionGuideTest extends AST2CPPTestBase {
|
||||||
//
|
//
|
||||||
// auto v = S(1);
|
// auto v = S(1);
|
||||||
public void testViaFunctionSetFromConstructors() throws Exception {
|
public void testViaFunctionSetFromConstructors() throws Exception {
|
||||||
parseAndCheckBindings(ScannerKind.STDCPP17);
|
parseAndCheckBindings(ScannerKind.STD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// template<class T> struct S{};
|
// template<class T> struct S{};
|
||||||
//
|
//
|
||||||
// S* pointer;
|
// S* pointer;
|
||||||
public void testNoDeductionForPointer() throws Exception {
|
public void testNoDeductionForPointer() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STDCPP17);
|
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STD);
|
||||||
IType pointedType = ((IPointerType) ((IVariable) bh.assertNonProblem("pointer")).getType()).getType();
|
IType pointedType = ((IPointerType) ((IVariable) bh.assertNonProblem("pointer")).getType()).getType();
|
||||||
assertTrue(pointedType instanceof IProblemType);
|
assertTrue(pointedType instanceof IProblemType);
|
||||||
bh.assertProblem("S*", 1);
|
bh.assertProblem("S*", 1);
|
||||||
|
@ -182,7 +182,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
|
||||||
//
|
//
|
||||||
// S* pointer;
|
// S* pointer;
|
||||||
public void testNoDeductionForPointerNoDefinition() throws Exception {
|
public void testNoDeductionForPointerNoDefinition() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STDCPP17);
|
BindingAssertionHelper bh = getAssertionHelper(ParserLanguage.CPP, ScannerKind.STD);
|
||||||
IType pointedType = ((IPointerType) ((IVariable) bh.assertNonProblem("pointer")).getType()).getType();
|
IType pointedType = ((IPointerType) ((IVariable) bh.assertNonProblem("pointer")).getType()).getType();
|
||||||
assertTrue(pointedType instanceof IProblemType);
|
assertTrue(pointedType instanceof IProblemType);
|
||||||
bh.assertProblem("S*", 1);
|
bh.assertProblem("S*", 1);
|
||||||
|
|
|
@ -27,8 +27,7 @@ import junit.framework.TestSuite;
|
||||||
*/
|
*/
|
||||||
public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTestBase {
|
public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTestBase {
|
||||||
private static void cxx17SetUp() {
|
private static void cxx17SetUp() {
|
||||||
// Enable deduction guides via C++17 feature detection macro
|
// Deduction guides are now enabled unconditionally
|
||||||
TestScannerProvider.sDefinedSymbols.put("__cpp_deduction_guides", "201703L");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void cxx17TearDown() {
|
private static void cxx17TearDown() {
|
||||||
|
|
|
@ -46,18 +46,4 @@ public interface ICPPASTTranslationUnit extends IASTTranslationUnit {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ICPPASTTranslationUnit copy(CopyStyle style);
|
public ICPPASTTranslationUnit copy(CopyStyle style);
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether this AST should enable class template argument deduction.
|
|
||||||
*
|
|
||||||
* @since 8.1
|
|
||||||
*/
|
|
||||||
public void setEnableClassTemplateArgumentDeduction(boolean flag);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether this AST should enable class template argument deduction.
|
|
||||||
*
|
|
||||||
* @since 8.1
|
|
||||||
*/
|
|
||||||
public boolean getEnableClassTemplateArgumentDeduction();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
|
||||||
private ICPPNamespace fBinding;
|
private ICPPNamespace fBinding;
|
||||||
private final CPPScopeMapper fScopeMapper;
|
private final CPPScopeMapper fScopeMapper;
|
||||||
private CPPASTAmbiguityResolver fAmbiguityResolver;
|
private CPPASTAmbiguityResolver fAmbiguityResolver;
|
||||||
private boolean fEnableClassTemplateArgumentDeduction;
|
|
||||||
|
|
||||||
// Caches.
|
// Caches.
|
||||||
private final Map<ICPPClassType, FinalOverriderMap> fFinalOverriderMapCache = new HashMap<>();
|
private final Map<ICPPClassType, FinalOverriderMap> fFinalOverriderMapCache = new HashMap<>();
|
||||||
|
@ -79,7 +78,6 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
|
||||||
@Override
|
@Override
|
||||||
public CPPASTTranslationUnit copy(CopyStyle style) {
|
public CPPASTTranslationUnit copy(CopyStyle style) {
|
||||||
CPPASTTranslationUnit copy = new CPPASTTranslationUnit();
|
CPPASTTranslationUnit copy = new CPPASTTranslationUnit();
|
||||||
copy.setEnableClassTemplateArgumentDeduction(getEnableClassTemplateArgumentDeduction());
|
|
||||||
return copy(copy, style);
|
return copy(copy, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,14 +278,4 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
|
||||||
public ICPPClassTemplatePartialSpecialization mapToAST(ICPPClassTemplatePartialSpecialization indexSpec) {
|
public ICPPClassTemplatePartialSpecialization mapToAST(ICPPClassTemplatePartialSpecialization indexSpec) {
|
||||||
return fScopeMapper.mapToAST(indexSpec);
|
return fScopeMapper.mapToAST(indexSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEnableClassTemplateArgumentDeduction(boolean flag) {
|
|
||||||
fEnableClassTemplateArgumentDeduction = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getEnableClassTemplateArgumentDeduction() {
|
|
||||||
return fEnableClassTemplateArgumentDeduction;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
private final boolean supportGCCStyleDesignators;
|
private final boolean supportGCCStyleDesignators;
|
||||||
private final boolean supportFoldExpression;
|
private final boolean supportFoldExpression;
|
||||||
private final boolean supportChar8TypeLiterals;
|
private final boolean supportChar8TypeLiterals;
|
||||||
private final boolean supportClassTemplateArgumentDeduction;
|
|
||||||
|
|
||||||
private final IIndex index;
|
private final IIndex index;
|
||||||
protected ICPPASTTranslationUnit translationUnit;
|
protected ICPPASTTranslationUnit translationUnit;
|
||||||
|
@ -251,7 +250,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
additionalNumericalSuffixes = scanner.getAdditionalNumericLiteralSuffixes();
|
additionalNumericalSuffixes = scanner.getAdditionalNumericLiteralSuffixes();
|
||||||
supportFoldExpression = true;
|
supportFoldExpression = true;
|
||||||
supportChar8TypeLiterals = scanner.getMacroDefinitions().containsKey("__cpp_char8_t"); //$NON-NLS-1$
|
supportChar8TypeLiterals = scanner.getMacroDefinitions().containsKey("__cpp_char8_t"); //$NON-NLS-1$
|
||||||
supportClassTemplateArgumentDeduction = scanner.getMacroDefinitions().containsKey("__cpp_deduction_guides"); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5609,8 +5607,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
((ASTTranslationUnit) translationUnit).setupBuiltinBindings(builtinBindingsProvider);
|
((ASTTranslationUnit) translationUnit).setupBuiltinBindings(builtinBindingsProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
translationUnit.setEnableClassTemplateArgumentDeduction(supportClassTemplateArgumentDeduction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void consumeArrayModifiers(DeclarationOptions option, List<IASTArrayModifier> collection)
|
private void consumeArrayModifiers(DeclarationOptions option, List<IASTArrayModifier> collection)
|
||||||
|
|
|
@ -780,18 +780,15 @@ public class CPPSemantics {
|
||||||
binding = user;
|
binding = user;
|
||||||
} else {
|
} else {
|
||||||
// Attempt class template argument deduction if appropriate
|
// Attempt class template argument deduction if appropriate
|
||||||
if (data.getTranslationUnit().getEnableClassTemplateArgumentDeduction()) {
|
if (lookupName.getParent() instanceof IASTIdExpression idExpression
|
||||||
if (lookupName.getParent() instanceof IASTIdExpression idExpression
|
&& idExpression.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
|
||||||
&& idExpression.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
|
|
||||||
|
|
||||||
// Class name for class type argument deduction is a type
|
// Class name for class type argument deduction is a type
|
||||||
return doClassTemplateArgumentDeduction((ICPPClassTemplate) binding, data);
|
return doClassTemplateArgumentDeduction((ICPPClassTemplate) binding, data);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
// Attempt class template argument deduction if appropriate
|
// Attempt class template argument deduction if appropriate
|
||||||
if (data.getTranslationUnit().getEnableClassTemplateArgumentDeduction()
|
if (lookupName.getParent() instanceof IASTNamedTypeSpecifier namedTypeSpecifier
|
||||||
&& lookupName.getParent() instanceof IASTNamedTypeSpecifier namedTypeSpecifier
|
|
||||||
&& namedTypeSpecifier.getPropertyInParent() == IASTSimpleDeclaration.DECL_SPECIFIER
|
&& namedTypeSpecifier.getPropertyInParent() == IASTSimpleDeclaration.DECL_SPECIFIER
|
||||||
&& namedTypeSpecifier.getParent() instanceof IASTSimpleDeclaration declaration) {
|
&& namedTypeSpecifier.getParent() instanceof IASTSimpleDeclaration declaration) {
|
||||||
|
|
||||||
|
@ -851,8 +848,7 @@ public class CPPSemantics {
|
||||||
} else {
|
} else {
|
||||||
// Name is qualified-name
|
// Name is qualified-name
|
||||||
// Attempt class template argument deduction if appropriate
|
// Attempt class template argument deduction if appropriate
|
||||||
if (data.getTranslationUnit().getEnableClassTemplateArgumentDeduction()
|
if (lookupName.getParent() instanceof ICPPASTQualifiedName qualifiedName
|
||||||
&& lookupName.getParent() instanceof ICPPASTQualifiedName qualifiedName
|
|
||||||
&& qualifiedName.getParent() instanceof IASTNamedTypeSpecifier namedTypeSpecifier
|
&& qualifiedName.getParent() instanceof IASTNamedTypeSpecifier namedTypeSpecifier
|
||||||
&& namedTypeSpecifier.getPropertyInParent() == IASTSimpleDeclaration.DECL_SPECIFIER
|
&& namedTypeSpecifier.getPropertyInParent() == IASTSimpleDeclaration.DECL_SPECIFIER
|
||||||
&& namedTypeSpecifier.getParent() instanceof IASTSimpleDeclaration declaration) {
|
&& namedTypeSpecifier.getParent() instanceof IASTSimpleDeclaration declaration) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue