summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2018-07-01 13:26:07 -0400
committerNathan Ridge2018-07-08 14:28:34 -0400
commit52e1ccf3bc64257067a6b512052eb28f0bebc033 (patch)
treec698ebfeef5f6823c48bac273928fa134c42b655
parent7f5ed929a93b72f09e71161f5483b91e6a224ff8 (diff)
downloadorg.eclipse.cdt-52e1ccf3bc64257067a6b512052eb28f0bebc033.tar.gz
org.eclipse.cdt-52e1ccf3bc64257067a6b512052eb28f0bebc033.tar.xz
org.eclipse.cdt-52e1ccf3bc64257067a6b512052eb28f0bebc033.zip
Bug 535777 - Disallow class body in trailing return type
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java12
3 files changed, 23 insertions, 5 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 0402f2bcab..39bc9c3fad 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
@@ -12710,4 +12710,15 @@ public class AST2CPPTests extends AST2CPPTestBase {
public void testStaticAssertWithoutMessage_534808() throws Exception {
parseAndCheckBindings();
}
+
+ // struct MyStruct {
+ // unsigned i;
+ // };
+ //
+ // auto myFunA() -> struct MyStruct {
+ // return {5};
+ // };
+ public void testElabSpecInTrailingReturn_535777() throws Exception {
+ parseAndCheckBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java
index 3408a09ae4..187d6c4d02 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/DeclarationOptions.java
@@ -30,6 +30,7 @@ public class DeclarationOptions {
final public static int ALLOW_OPAQUE_ENUM= 0x2000;
final public static int SINGLE_DTOR= 0x4000;
final public static int ALLOW_FUNCTION_DEFINITION= 0x8000;
+ final public static int NO_COMPOSITE_SPECIFIER= 0x10000;
public static final DeclarationOptions
GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_OPAQUE_ENUM | ALLOW_FUNCTION_DEFINITION),
@@ -39,7 +40,7 @@ public class DeclarationOptions {
LOCAL= new DeclarationOptions(ALLOW_OPAQUE_ENUM),
PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME | NO_BRACED_INITIALIZER | NO_CTOR_STYLE_INITIALIZER),
TYPEID= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER),
- TYPEID_TRAILING_RETURN_TYPE= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | ALLOW_FOLLOWED_BY_BRACE | ALLOW_FUNCTION_DEFINITION),
+ TYPEID_TRAILING_RETURN_TYPE= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | ALLOW_FOLLOWED_BY_BRACE | ALLOW_FUNCTION_DEFINITION | NO_COMPOSITE_SPECIFIER),
TYPEID_NEW= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED | ALLOW_FOLLOWED_BY_BRACE),
TYPEID_CONVERSION= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED),
EXCEPTION= new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER),
@@ -62,6 +63,7 @@ public class DeclarationOptions {
final public boolean fAllowOpaqueEnum;
final public boolean fSingleDtor;
final public boolean fAllowFunctionDefinition;
+ final public boolean fAllowCompositeSpecifier;
public DeclarationOptions(int options) {
fAllowEmptySpecifier= (options & ALLOW_EMPTY_SPECIFIER) != 0;
@@ -79,5 +81,6 @@ public class DeclarationOptions {
fAllowOpaqueEnum= (options & ALLOW_OPAQUE_ENUM) != 0;
fSingleDtor= (options & SINGLE_DTOR) != 0;
fAllowFunctionDefinition= (options & ALLOW_FUNCTION_DEFINITION) != 0;
+ fAllowCompositeSpecifier= (options & NO_COMPOSITE_SPECIFIER) == 0;
}
}
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 c3c193cdea..8ba5be4d04 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
@@ -3434,10 +3434,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
case IToken.t_union:
if (encounteredTypename || encounteredRawType)
break declSpecifiers;
- try {
- result= classSpecifier();
- } catch (BacktrackException bt) {
- result= elaboratedTypeSpecifier();
+ if (option != null && option.fAllowCompositeSpecifier) {
+ try {
+ result= classSpecifier();
+ } catch (BacktrackException bt) {
+ result= elaboratedTypeSpecifier();
+ }
+ } else {
+ result = elaboratedTypeSpecifier();
}
endOffset= calculateEndOffset(result);
encounteredTypename= true;