mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +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 {
|
||||
// throw "exception";
|
||||
// }
|
||||
public void testAttributedFunction() throws Exception {
|
||||
public void testTrailingNoreturnFunctionDefinition() throws Exception {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||
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{};
|
||||
public void testAttributedClass() throws Exception {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||
|
|
|
@ -143,12 +143,20 @@ public class CPPFunctionTests extends PDOMTestBase {
|
|||
assertTrue(((ICPPFunction) bindings[0]).takesVarArgs());
|
||||
}
|
||||
|
||||
public void testNoReturnCPPFunction() throws Exception {
|
||||
IBinding[] bindings = findQualifiedName(pdom, "noReturnCPPFunction");
|
||||
private void assertNoReturnFunction(String functionName) throws CoreException {
|
||||
IBinding[] bindings = findQualifiedName(pdom, functionName);
|
||||
assertEquals(1, bindings.length);
|
||||
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 {
|
||||
assertType(pdom, "forwardDeclaration", ICPPFunction.class);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,10 @@ extern float externCPPFunction(int p1);
|
|||
inline void inlineCPPFunction(long p1);
|
||||
void varArgsCPPFunction(int p1, ...);
|
||||
void noReturnCPPFunction() __attribute__((noreturn));
|
||||
[[noreturn]] void trailingNoReturnStdAttributeDecl();
|
||||
void leadingNoReturnStdAttributeDecl() [[noreturn]];
|
||||
[[noreturn]] void trailingNoReturnStdAttributeDef(){}
|
||||
void leadingNoReturnStdAttributeDef() [[noreturn]]{}
|
||||
|
||||
void voidCPPFunction();
|
||||
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.ast.ASTTypeUtil;
|
||||
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.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
|
@ -663,7 +664,17 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
@Override
|
||||
public boolean isNoReturn() {
|
||||
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue