1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 10:15:39 +02:00

Bug 535777 - Disallow class body in trailing return type

Change-Id: I6e4d015cb3e1b12486f336db94ed71c234142b60
This commit is contained in:
Nathan Ridge 2018-07-01 13:26:07 -04:00
parent 7f5ed929a9
commit 52e1ccf3bc
3 changed files with 23 additions and 5 deletions

View file

@ -12710,4 +12710,15 @@ public class AST2CPPTests extends AST2CPPTestBase {
public void testStaticAssertWithoutMessage_534808() throws Exception { public void testStaticAssertWithoutMessage_534808() throws Exception {
parseAndCheckBindings(); parseAndCheckBindings();
} }
// struct MyStruct {
// unsigned i;
// };
//
// auto myFunA() -> struct MyStruct {
// return {5};
// };
public void testElabSpecInTrailingReturn_535777() throws Exception {
parseAndCheckBindings();
}
} }

View file

@ -30,6 +30,7 @@ public class DeclarationOptions {
final public static int ALLOW_OPAQUE_ENUM= 0x2000; final public static int ALLOW_OPAQUE_ENUM= 0x2000;
final public static int SINGLE_DTOR= 0x4000; final public static int SINGLE_DTOR= 0x4000;
final public static int ALLOW_FUNCTION_DEFINITION= 0x8000; final public static int ALLOW_FUNCTION_DEFINITION= 0x8000;
final public static int NO_COMPOSITE_SPECIFIER= 0x10000;
public static final DeclarationOptions public static final DeclarationOptions
GLOBAL= new DeclarationOptions(ALLOW_EMPTY_SPECIFIER | ALLOW_OPAQUE_ENUM | ALLOW_FUNCTION_DEFINITION), 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), LOCAL= new DeclarationOptions(ALLOW_OPAQUE_ENUM),
PARAMETER= new DeclarationOptions(ALLOW_ABSTRACT | ALLOW_PARAMETER_PACKS | REQUIRE_SIMPLE_NAME | NO_BRACED_INITIALIZER | NO_CTOR_STYLE_INITIALIZER), 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= 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_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), TYPEID_CONVERSION= new DeclarationOptions(REQUIRE_ABSTRACT | NO_INITIALIZER | NO_FUNCTIONS | NO_NESTED),
EXCEPTION= new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER), EXCEPTION= new DeclarationOptions(ALLOW_ABSTRACT | NO_INITIALIZER),
@ -62,6 +63,7 @@ public class DeclarationOptions {
final public boolean fAllowOpaqueEnum; final public boolean fAllowOpaqueEnum;
final public boolean fSingleDtor; final public boolean fSingleDtor;
final public boolean fAllowFunctionDefinition; final public boolean fAllowFunctionDefinition;
final public boolean fAllowCompositeSpecifier;
public DeclarationOptions(int options) { public DeclarationOptions(int options) {
fAllowEmptySpecifier= (options & ALLOW_EMPTY_SPECIFIER) != 0; fAllowEmptySpecifier= (options & ALLOW_EMPTY_SPECIFIER) != 0;
@ -79,5 +81,6 @@ public class DeclarationOptions {
fAllowOpaqueEnum= (options & ALLOW_OPAQUE_ENUM) != 0; fAllowOpaqueEnum= (options & ALLOW_OPAQUE_ENUM) != 0;
fSingleDtor= (options & SINGLE_DTOR) != 0; fSingleDtor= (options & SINGLE_DTOR) != 0;
fAllowFunctionDefinition= (options & ALLOW_FUNCTION_DEFINITION) != 0; fAllowFunctionDefinition= (options & ALLOW_FUNCTION_DEFINITION) != 0;
fAllowCompositeSpecifier= (options & NO_COMPOSITE_SPECIFIER) == 0;
} }
} }

View file

@ -3434,11 +3434,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
case IToken.t_union: case IToken.t_union:
if (encounteredTypename || encounteredRawType) if (encounteredTypename || encounteredRawType)
break declSpecifiers; break declSpecifiers;
if (option != null && option.fAllowCompositeSpecifier) {
try { try {
result= classSpecifier(); result= classSpecifier();
} catch (BacktrackException bt) { } catch (BacktrackException bt) {
result= elaboratedTypeSpecifier(); result= elaboratedTypeSpecifier();
} }
} else {
result = elaboratedTypeSpecifier();
}
endOffset= calculateEndOffset(result); endOffset= calculateEndOffset(result);
encounteredTypename= true; encounteredTypename= true;
break; break;