Skip to content

Commit 68df69e

Browse files
committed
Test constexpr execution of if statement with static_assert declaration substatement
1 parent 62c1f68 commit 68df69e

File tree

7 files changed

+41
-2
lines changed

7 files changed

+41
-2
lines changed

core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
105105
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
106106
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
107+
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
107108
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
108109
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
109110
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
@@ -11781,4 +11782,32 @@ public void testRecognizeConstructorWithSemicolonAfterBody() throws Exception {
1178111782
public void testAllowAggregateInitializationInTemplateBody() throws Exception {
1178211783
parseAndCheckImplicitNameBindings();
1178311784
}
11785+
11786+
// template<typename T>
11787+
// constexpr bool if_false(T t) {
11788+
// if (t)
11789+
// static_assert(false);
11790+
// else
11791+
// return true;
11792+
// }
11793+
// template<typename T>
11794+
// constexpr bool if_true(T t) {
11795+
// if (t)
11796+
// return true;
11797+
// else
11798+
// static_assert(false);
11799+
// }
11800+
// static constexpr auto value_if_false = if_false(true);
11801+
// static constexpr auto value_if_true = if_true(false);
11802+
public void testIfThenElseClauseStaticAssert() throws Exception {
11803+
BindingAssertionHelper helper = getAssertionHelper();
11804+
11805+
// initial value must be available, but it's value is wrong because static_assert() is not supported (yet)
11806+
CPPVariable valueIfFalse = helper.assertNonProblem("value_if_false");
11807+
assertEquals(IntegralValue.STATIC_ASSERT_FAILED_ERROR, valueIfFalse.getInitialValue());
11808+
11809+
// initial value must be available, but it's value is wrong because static_assert() is not supported (yet)
11810+
CPPVariable valueIfTrue = helper.assertNonProblem("value_if_true");
11811+
assertEquals(IntegralValue.STATIC_ASSERT_FAILED_ERROR, valueIfTrue.getInitialValue());
11812+
}
1178411813
}

core/org.eclipse.cdt.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
5-
Bundle-Version: 9.2.100.qualifier
5+
Bundle-Version: 9.3.0.qualifier
66
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ISemanticProblem.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public interface ISemanticProblem {
5757
/** @since 6.9 */
5858
int TYPE_CANNOT_DEDUCE_STRUCTURED_BINDING_TYPE = 10009;
5959

60+
/** @since 9.3 */
61+
int TYPE_STATIC_ASSERT_FAILED = 10010;
62+
6063
/**
6164
* Returns the ID of the problem.
6265
*/

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IntegralValue.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public void setSubValue(int position, ICPPEvaluation newValue) {
5151
// IntegralValue.ERROR indicates that an error, such as a substitution failure, occurred during evaluation.
5252
public static final IntegralValue ERROR = new IntegralValue("<error>".toCharArray()); //$NON-NLS-1$
5353

54+
public static final IntegralValue STATIC_ASSERT_FAILED_ERROR = new IntegralValue(
55+
"<static assert failed>".toCharArray()); //$NON-NLS-1$
56+
5457
public static final IntegralValue NOT_INITIALIZED = new IntegralValue("<__>".toCharArray()); //$NON-NLS-1$
5558

5659
private static final char UNIQUE_CHAR = '_';

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class ProblemType implements IProblemType, ISerializableType {
3535
public static final IType RECURSION_IN_LOOKUP = new ProblemType(BINDING_RECURSION_IN_LOOKUP);
3636
public static final IType UNKNOWN_FOR_EXPRESSION = new ProblemType(TYPE_UNKNOWN_FOR_EXPRESSION);
3737
public static final IType UNRESOLVED_NAME = new ProblemType(TYPE_UNRESOLVED_NAME);
38+
public static final IType STATIC_ASSERT_FAILED = new ProblemType(TYPE_STATIC_ASSERT_FAILED);
3839

3940
private final int fID;
4041

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ private static String getProblemKey(int id) {
132132
return "ISemanticProblem.TYPE_CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE";
133133
case ISemanticProblem.TYPE_AUTO_FOR_VIRTUAL_METHOD:
134134
return "ISemanticProblem.TYPE_AUTO_FOR_VIRTUAL_METHOD";
135+
case ISemanticProblem.TYPE_STATIC_ASSERT_FAILED:
136+
return "ISemanticProblem.TYPE_STATIC_ASSERT_FAILED";
135137
}
136138
return null;
137139
}

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION=Failure to determine type of expres
8181
ISemanticProblem.TYPE_NOT_PERSISTED=Failure to store type in the index
8282
ISemanticProblem.TYPE_ENUMERATION_EXPECTED=Enumeration expected
8383
ISemanticProblem.TYPE_CANNOT_DEDUCE_DECLTYPE_AUTO_TYPE=Failure to determine decltype(auto)-type
84-
ISemanticProblem.TYPE_AUTO_FOR_VIRTUAL_METHOD=Illegally auto-typed virtual method
84+
ISemanticProblem.TYPE_AUTO_FOR_VIRTUAL_METHOD=Illegally auto-typed virtual method
85+
ISemanticProblem.TYPE_STATIC_ASSERT_FAILED=Static assertion failed

0 commit comments

Comments
 (0)