Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2008-04-15 03:35:01 -0400
committerMarkus Schorn2008-04-15 03:35:01 -0400
commit9594a52283a67833d55266d600902b09324215b7 (patch)
treeaf223e941182dddb5f3a2c529aa386e33a621d58 /core
parentdf9250870553a0c3012a8569a91422cc9477176e (diff)
downloadorg.eclipse.cdt-9594a52283a67833d55266d600902b09324215b7.tar.gz
org.eclipse.cdt-9594a52283a67833d55266d600902b09324215b7.tar.xz
org.eclipse.cdt-9594a52283a67833d55266d600902b09324215b7.zip
Using 'typename' in expressions, bug 227082.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java23
2 files changed, 16 insertions, 18 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index 560506012e6..e5acde4170c 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -4513,4 +4513,15 @@ public class AST2Tests extends AST2BaseTest {
parseAndCheckBindings(code, ParserLanguage.C, true);
parseAndCheckBindings(code, ParserLanguage.CPP, true);
}
+
+ // template<typename T> class X {
+ // typename T::t func() {
+ // return typename T::t();
+ // }
+ // };
+ public void testTypenameInExpression() throws Exception {
+ final String code = getAboveComment();
+ parseAndCheckBindings(code, ParserLanguage.CPP);
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index df4c2781ba2..9480aa20675 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -1319,7 +1319,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
switch (LT(1)) {
case IToken.t_typename:
- int o = consume().getOffset();
+ int typenameOffset= consume().getOffset();
boolean templateTokenConsumed = false;
if (LT(1) == IToken.t_template) {
@@ -1328,28 +1328,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
ITokenDuple nestedName = name();
IASTName name = createName(nestedName);
-
- consume(IToken.tLPAREN);
- int lastOffset;
- IASTExpression expressionList;
- if (templateIdScopes.size() > 0) {
- templateIdScopes.push(IToken.tLPAREN);
- }
- try {
- expressionList = expression();
- lastOffset = consume(IToken.tRPAREN).getEndOffset();
- }
- finally {
- if (templateIdScopes.size() > 0) {
- templateIdScopes.pop();
- }
+ if (LT(1) != IToken.tLPAREN) {
+ throwBacktrack(nestedName.getFirstToken().getOffset(), nestedName.getLastToken().getEndOffset());
}
ICPPASTTypenameExpression result = createTypenameExpression();
- ((ASTNode) result).setOffsetAndLength(o, lastOffset - o);
+ ((ASTNode) result).setOffsetAndLength(typenameOffset, nestedName.getLastToken().getEndOffset() - typenameOffset);
result.setIsTemplate(templateTokenConsumed);
result.setName(name);
- result.setInitialValue(expressionList);
firstExpression = result;
break;
// simple-type-specifier ( assignment-expression , .. )
@@ -1396,6 +1382,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
firstExpression = specialCastExpression(ICPPASTCastExpression.op_const_cast);
break;
case IToken.t_typeid:
+ int lastOffset;
int so = consume().getOffset();
consume(IToken.tLPAREN);
if (templateIdScopes.size() > 0) {

Back to the top