mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 02:05:39 +02:00
Bug 535777 - Disallow class body in trailing return type
Change-Id: I6e4d015cb3e1b12486f336db94ed71c234142b60
This commit is contained in:
parent
7f5ed929a9
commit
52e1ccf3bc
3 changed files with 23 additions and 5 deletions
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3434,10 +3434,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
case IToken.t_union:
|
case IToken.t_union:
|
||||||
if (encounteredTypename || encounteredRawType)
|
if (encounteredTypename || encounteredRawType)
|
||||||
break declSpecifiers;
|
break declSpecifiers;
|
||||||
try {
|
if (option != null && option.fAllowCompositeSpecifier) {
|
||||||
result= classSpecifier();
|
try {
|
||||||
} catch (BacktrackException bt) {
|
result= classSpecifier();
|
||||||
result= elaboratedTypeSpecifier();
|
} catch (BacktrackException bt) {
|
||||||
|
result= elaboratedTypeSpecifier();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = elaboratedTypeSpecifier();
|
||||||
}
|
}
|
||||||
endOffset= calculateEndOffset(result);
|
endOffset= calculateEndOffset(result);
|
||||||
encounteredTypename= true;
|
encounteredTypename= true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue