1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Make c++17 deduction guides unconditionally enabled

This commit is contained in:
Igor V. Kovalenko 2023-04-22 09:45:03 +03:00 committed by Jonah Graham
parent 7d1ea08ae0
commit a1c904fbc7
7 changed files with 16 additions and 68 deletions

View file

@ -112,12 +112,6 @@ public abstract class AST2TestBase extends SemanticTestBase {
return true;
}
},
STDCPP17 {
@Override
public boolean isUseGNUExtensions() {
return false;
}
},
STDCPP20 {
@Override
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 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 Map<String, String> getGnuMap() {
@ -161,18 +154,10 @@ public abstract class AST2TestBase extends SemanticTestBase {
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() {
Map<String, String> map = getStdCpp17Map();
Map<String, String> map = getStdMap();
map.put("__cpp_impl_three_way_comparison", "201907L");
map.put("__cpp_char8_t", "201811L");
// TODO: C++20 features
//map.put("__cpp_deduction_guides", "201907L");
return map;
}
@ -256,8 +241,6 @@ public abstract class AST2TestBase extends SemanticTestBase {
switch (scannerKind) {
case GNU:
return GNU_SCANNER_INFO;
case STDCPP17:
return STDCPP17_SCANNER_INFO;
case STDCPP20:
return STDCPP20_SCANNER_INFO;
case STD:

View file

@ -53,7 +53,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
// S convert(ddouble);
// }
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("dint = S", 4), double_);
assertType(bh.assertNonProblem("dv = S", 2), double_);
@ -85,7 +85,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
// int iv = S(1).value;
// }
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("dint = S", 4), double_);
assertType(bh.assertNonProblem("dv = S", 2), double_);
@ -107,7 +107,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
// S convert(ddouble);
// }
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);
assertType(bh.assertNonProblem("dchar = S", 5), varChar.getType());
@ -131,7 +131,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
// UniquePtr dp{new auto(2.0)};
// auto da = dp;
public void testMinimal() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP17);
parseAndCheckBindings(ScannerKind.STD);
}
// template<class T> struct S {
@ -146,7 +146,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
//
// S s2;
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);
bh.assertProblem("S s1", 1);
bh.assertNonProblem("S s2", 1);
@ -165,14 +165,14 @@ public class DeductionGuideTest extends AST2CPPTestBase {
//
// auto v = S(1);
public void testViaFunctionSetFromConstructors() throws Exception {
parseAndCheckBindings(ScannerKind.STDCPP17);
parseAndCheckBindings(ScannerKind.STD);
}
// template<class T> struct S{};
//
// S* pointer;
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();
assertTrue(pointedType instanceof IProblemType);
bh.assertProblem("S*", 1);
@ -182,7 +182,7 @@ public class DeductionGuideTest extends AST2CPPTestBase {
//
// S* pointer;
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();
assertTrue(pointedType instanceof IProblemType);
bh.assertProblem("S*", 1);

View file

@ -27,8 +27,7 @@ import junit.framework.TestSuite;
*/
public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTestBase {
private static void cxx17SetUp() {
// Enable deduction guides via C++17 feature detection macro
TestScannerProvider.sDefinedSymbols.put("__cpp_deduction_guides", "201703L");
// Deduction guides are now enabled unconditionally
}
private static void cxx17TearDown() {

View file

@ -46,18 +46,4 @@ public interface ICPPASTTranslationUnit extends IASTTranslationUnit {
*/
@Override
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();
}

View file

@ -56,7 +56,6 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
private ICPPNamespace fBinding;
private final CPPScopeMapper fScopeMapper;
private CPPASTAmbiguityResolver fAmbiguityResolver;
private boolean fEnableClassTemplateArgumentDeduction;
// Caches.
private final Map<ICPPClassType, FinalOverriderMap> fFinalOverriderMapCache = new HashMap<>();
@ -79,7 +78,6 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
@Override
public CPPASTTranslationUnit copy(CopyStyle style) {
CPPASTTranslationUnit copy = new CPPASTTranslationUnit();
copy.setEnableClassTemplateArgumentDeduction(getEnableClassTemplateArgumentDeduction());
return copy(copy, style);
}
@ -280,14 +278,4 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
public ICPPClassTemplatePartialSpecialization mapToAST(ICPPClassTemplatePartialSpecialization indexSpec) {
return fScopeMapper.mapToAST(indexSpec);
}
@Override
public void setEnableClassTemplateArgumentDeduction(boolean flag) {
fEnableClassTemplateArgumentDeduction = flag;
}
@Override
public boolean getEnableClassTemplateArgumentDeduction() {
return fEnableClassTemplateArgumentDeduction;
}
}

View file

@ -211,7 +211,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private final boolean supportGCCStyleDesignators;
private final boolean supportFoldExpression;
private final boolean supportChar8TypeLiterals;
private final boolean supportClassTemplateArgumentDeduction;
private final IIndex index;
protected ICPPASTTranslationUnit translationUnit;
@ -251,7 +250,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
additionalNumericalSuffixes = scanner.getAdditionalNumericLiteralSuffixes();
supportFoldExpression = true;
supportChar8TypeLiterals = scanner.getMacroDefinitions().containsKey("__cpp_char8_t"); //$NON-NLS-1$
supportClassTemplateArgumentDeduction = scanner.getMacroDefinitions().containsKey("__cpp_deduction_guides"); //$NON-NLS-1$
}
@Override
@ -5609,8 +5607,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
((ASTTranslationUnit) translationUnit).setupBuiltinBindings(builtinBindingsProvider);
}
}
translationUnit.setEnableClassTemplateArgumentDeduction(supportClassTemplateArgumentDeduction);
}
private void consumeArrayModifiers(DeclarationOptions option, List<IASTArrayModifier> collection)

View file

@ -780,18 +780,15 @@ public class CPPSemantics {
binding = user;
} else {
// Attempt class template argument deduction if appropriate
if (data.getTranslationUnit().getEnableClassTemplateArgumentDeduction()) {
if (lookupName.getParent() instanceof IASTIdExpression idExpression
&& idExpression.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
if (lookupName.getParent() instanceof IASTIdExpression idExpression
&& idExpression.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
// Class name for class type argument deduction is a type
return doClassTemplateArgumentDeduction((ICPPClassTemplate) binding, data);
}
// Class name for class type argument deduction is a type
return doClassTemplateArgumentDeduction((ICPPClassTemplate) binding, data);
}
boolean ok = false;
// Attempt class template argument deduction if appropriate
if (data.getTranslationUnit().getEnableClassTemplateArgumentDeduction()
&& lookupName.getParent() instanceof IASTNamedTypeSpecifier namedTypeSpecifier
if (lookupName.getParent() instanceof IASTNamedTypeSpecifier namedTypeSpecifier
&& namedTypeSpecifier.getPropertyInParent() == IASTSimpleDeclaration.DECL_SPECIFIER
&& namedTypeSpecifier.getParent() instanceof IASTSimpleDeclaration declaration) {
@ -851,8 +848,7 @@ public class CPPSemantics {
} else {
// Name is qualified-name
// Attempt class template argument deduction if appropriate
if (data.getTranslationUnit().getEnableClassTemplateArgumentDeduction()
&& lookupName.getParent() instanceof ICPPASTQualifiedName qualifiedName
if (lookupName.getParent() instanceof ICPPASTQualifiedName qualifiedName
&& qualifiedName.getParent() instanceof IASTNamedTypeSpecifier namedTypeSpecifier
&& namedTypeSpecifier.getPropertyInParent() == IASTSimpleDeclaration.DECL_SPECIFIER
&& namedTypeSpecifier.getParent() instanceof IASTSimpleDeclaration declaration) {