Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java5
4 files changed, 41 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 74d7b0a0358..cc62e33d4a4 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -12991,4 +12991,31 @@ public class AST2CPPTests extends AST2CPPTestBase {
public void testBraceElisionForAggregateInit6_typedef_543038() throws Exception {
parseAndCheckBindings();
}
+
+ // struct type{
+ // int a;
+ // };
+ // type b{sizeof(type)};
+ public void testAggregateInitNoNarrowingConversionInConstContext_545756() throws Exception {
+ parseAndCheckImplicitNameBindings();
+ }
+
+ // struct type{
+ // int a;
+ // };
+ // const unsigned long v = 1;
+ // type b{v};
+ public void testAggregateInitNoNarrowingConversionInConstContext2_545756() throws Exception {
+ parseAndCheckImplicitNameBindings();
+ }
+
+ // struct type{
+ // int a;
+ // };
+ // unsigned long v = 1;
+ // type b{v};
+ public void testAggregateInitNarrowingConversion_545756() throws Exception {
+ BindingAssertionHelper bh = getAssertionHelper();
+ bh.assertImplicitName("b{v};", 1, IProblemBinding.class);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
index e3afebd2e6b..d18585b19d5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AggregateInitialization.java
@@ -76,7 +76,7 @@ class AggregateInitialization {
if (!cost.converts()) {
return cost;
}
- // If the initializer-clause is an expression and a narrowing conversion is
+ // [dcl.init.aggr] If the initializer-clause is an expression and a narrowing conversion is
// required to convert the expression, the program is ill-formed.
if (!(initializer instanceof EvalInitList) && cost.isNarrowingConversion()) {
return Cost.NO_CONVERSION;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index 4a735d94472..fd240c4c9d6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -67,6 +67,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
+import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -2148,6 +2149,14 @@ public class CPPVisitor extends ASTQueries {
IASTNode initClause = declarator.getInitializer();
if (initClause instanceof IASTEqualsInitializer) {
initClause = ((IASTEqualsInitializer) initClause).getInitializerClause();
+ if (initClause instanceof IASTLiteralExpression && SemanticUtil.isConst(type)) {
+ IType t = SemanticUtil.getNestedType(type, TDEF | ALLCVQ);
+ if (t instanceof CPPBasicType) {
+ IValue v = SemanticUtil.getValueOfInitializer(declarator.getInitializer(), t);
+ if (v.numberValue() != null)
+ ((CPPBasicType) t).setAssociatedNumericalValue(v.numberValue().longValue());
+ }
+ }
}
if (initClause instanceof IASTInitializerList) {
IType t = SemanticUtil.getNestedType(type, TDEF);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java
index bf8bb5ca297..e08dce34c89 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalUnaryTypeID.java
@@ -160,7 +160,10 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation {
case op_sizeof:
case op_sizeofParameterPack:
case op_alignof:
- return CPPVisitor.get_SIZE_T();
+ CPPBasicType t = (CPPBasicType) CPPVisitor.get_SIZE_T().clone();
+ if (getValue().numberValue() != null)
+ t.setAssociatedNumericalValue(getValue().numberValue().longValue());
+ return t;
case op_typeid:
return CPPVisitor.get_type_info();
case op_has_nothrow_copy:

Back to the top