Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2012-01-11 07:49:44 -0500
committerMarkus Schorn2012-01-11 07:49:44 -0500
commit8aef9f4f9d9cf3ddd82daacd6d900d6e853d7930 (patch)
treee7ffbed55ebf1fa76c253dad9d434d9944706dd7
parentb68ecdc716854333250c85d67533b84249b0b1dd (diff)
downloadorg.eclipse.cdt-8aef9f4f9d9cf3ddd82daacd6d900d6e853d7930.tar.gz
org.eclipse.cdt-8aef9f4f9d9cf3ddd82daacd6d900d6e853d7930.tar.xz
org.eclipse.cdt-8aef9f4f9d9cf3ddd82daacd6d900d6e853d7930.zip
Bug 368309: Value for sizeof expression
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java17
2 files changed, 20 insertions, 7 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
index d6afa8b302..7cd2e58936 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
@@ -5713,4 +5713,14 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testPartialClassTemplateSpecUsingDefaultArgument_367997() throws Exception {
parseAndCheckBindings();
}
+
+ // struct two { char x[2]; };
+ // two check(...);
+ // char check(int);
+ // template <int> struct foo {};
+ // template <> struct foo<1> { typedef int type; };
+ // typedef foo<sizeof(check(0))>::type t; // ERROR HERE
+ public void testValueForSizeofExpression_368309() throws Exception {
+ parseAndCheckBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
index 5d212fc4ee..0e635c650f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java
@@ -580,13 +580,16 @@ public class Value implements IValue {
final int unaryOp= ue.getOperator();
if (unaryOp == IASTUnaryExpression.op_sizeof) {
- IType type = ue.getExpressionType();
- ASTTranslationUnit ast = (ASTTranslationUnit) ue.getTranslationUnit();
- SizeofCalculator calculator = ast.getSizeofCalculator();
- SizeAndAlignment info = calculator.sizeAndAlignment(type);
- if (info == null)
- throw UNKNOWN_EX;
- return info.size;
+ final IASTExpression operand = ue.getOperand();
+ if (operand != null) {
+ IType type = operand.getExpressionType();
+ ASTTranslationUnit ast = (ASTTranslationUnit) ue.getTranslationUnit();
+ SizeofCalculator calculator = ast.getSizeofCalculator();
+ SizeAndAlignment info = calculator.sizeAndAlignment(type);
+ if (info != null)
+ return info.size;
+ }
+ throw UNKNOWN_EX;
}
if (unaryOp == IASTUnaryExpression.op_amper || unaryOp == IASTUnaryExpression.op_star ||

Back to the top