mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 516298 - Improved recognition of [[noreturn]] attribute
Change-Id: I275f0ee38045600c104d5ed7e2c14fec04eac046 Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
parent
fb898b6088
commit
0f27b20848
4 changed files with 47 additions and 4 deletions
|
@ -278,11 +278,31 @@ public class AST2CPPAttributeTests extends AST2TestBase {
|
||||||
// void foo() throw(char const *) [[noreturn]] -> void {
|
// void foo() throw(char const *) [[noreturn]] -> void {
|
||||||
// throw "exception";
|
// throw "exception";
|
||||||
// }
|
// }
|
||||||
public void testAttributedFunction() throws Exception {
|
public void testTrailingNoreturnFunctionDefinition() throws Exception {
|
||||||
IASTTranslationUnit tu = parseAndCheckBindings();
|
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||||
checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDeclarator.class);
|
checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDeclarator.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [[noreturn]] void foo() throw(char const *) {
|
||||||
|
// throw "exception";
|
||||||
|
// }
|
||||||
|
public void testLeadingNoreturnFunctionDefinition() throws Exception {
|
||||||
|
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||||
|
checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDefinition.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// void foo() throw(char const *) [[noreturn]];
|
||||||
|
public void testTrailingNoReturnFunctionDeclaration() throws Exception {
|
||||||
|
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||||
|
checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDeclarator.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [[noreturn]] void foo() throw(char const *);
|
||||||
|
public void testLeadingNoReturnFunctionDeclaration() throws Exception {
|
||||||
|
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||||
|
checkAttributeRelations(getAttributeSpecifiers(tu), IASTSimpleDeclaration.class);
|
||||||
|
}
|
||||||
|
|
||||||
// class [[attr]] C{};
|
// class [[attr]] C{};
|
||||||
public void testAttributedClass() throws Exception {
|
public void testAttributedClass() throws Exception {
|
||||||
IASTTranslationUnit tu = parseAndCheckBindings();
|
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||||
|
|
|
@ -143,12 +143,20 @@ public class CPPFunctionTests extends PDOMTestBase {
|
||||||
assertTrue(((ICPPFunction) bindings[0]).takesVarArgs());
|
assertTrue(((ICPPFunction) bindings[0]).takesVarArgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoReturnCPPFunction() throws Exception {
|
private void assertNoReturnFunction(String functionName) throws CoreException {
|
||||||
IBinding[] bindings = findQualifiedName(pdom, "noReturnCPPFunction");
|
IBinding[] bindings = findQualifiedName(pdom, functionName);
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
assertTrue(((ICPPFunction) bindings[0]).isNoReturn());
|
assertTrue(((ICPPFunction) bindings[0]).isNoReturn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNoReturnCPPFunction() throws Exception {
|
||||||
|
assertNoReturnFunction("noReturnCPPFunction");
|
||||||
|
assertNoReturnFunction("trailingNoReturnStdAttributeDecl");
|
||||||
|
assertNoReturnFunction("leadingNoReturnStdAttributeDecl");
|
||||||
|
assertNoReturnFunction("trailingNoReturnStdAttributeDef");
|
||||||
|
assertNoReturnFunction("leadingNoReturnStdAttributeDef");
|
||||||
|
}
|
||||||
|
|
||||||
public void testForwardDeclarationType() throws Exception {
|
public void testForwardDeclarationType() throws Exception {
|
||||||
assertType(pdom, "forwardDeclaration", ICPPFunction.class);
|
assertType(pdom, "forwardDeclaration", ICPPFunction.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,10 @@ extern float externCPPFunction(int p1);
|
||||||
inline void inlineCPPFunction(long p1);
|
inline void inlineCPPFunction(long p1);
|
||||||
void varArgsCPPFunction(int p1, ...);
|
void varArgsCPPFunction(int p1, ...);
|
||||||
void noReturnCPPFunction() __attribute__((noreturn));
|
void noReturnCPPFunction() __attribute__((noreturn));
|
||||||
|
[[noreturn]] void trailingNoReturnStdAttributeDecl();
|
||||||
|
void leadingNoReturnStdAttributeDecl() [[noreturn]];
|
||||||
|
[[noreturn]] void trailingNoReturnStdAttributeDef(){}
|
||||||
|
void leadingNoReturnStdAttributeDef() [[noreturn]]{}
|
||||||
|
|
||||||
void voidCPPFunction();
|
void voidCPPFunction();
|
||||||
int intCPPFunction();
|
int intCPPFunction();
|
||||||
|
|
|
@ -18,6 +18,7 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
|
||||||
import org.eclipse.cdt.core.dom.ILinkage;
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
@ -663,7 +664,17 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
@Override
|
@Override
|
||||||
public boolean isNoReturn() {
|
public boolean isNoReturn() {
|
||||||
ICPPASTFunctionDeclarator dtor = getPreferredDtor();
|
ICPPASTFunctionDeclarator dtor = getPreferredDtor();
|
||||||
return dtor != null && AttributeUtil.hasNoreturnAttribute(dtor);
|
if (dtor == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (AttributeUtil.hasNoreturnAttribute(dtor)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
IASTNode parent = dtor.getParent();
|
||||||
|
if (parent instanceof IASTAttributeOwner) {
|
||||||
|
return AttributeUtil.hasNoreturnAttribute((IASTAttributeOwner) parent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ICPPExecution getFunctionBodyExecution(ICPPFunction function, IASTNode point) {
|
public static ICPPExecution getFunctionBodyExecution(ICPPFunction function, IASTNode point) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue