Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] CPPASTTemplateIDAmbiguity is not resolved inside noexcept

Hi Macro,

This is definitely a bug. CPPASTFunctionDeclarator.replace() should be considering the noexcept-_expression_ as a possible node to replace.

Please file a bug in the bug tracker. Thanks!


From: marco.syfrig@xxxxxxxxx
Date: Tue, 12 May 2015 12:04:07 +0000
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] CPPASTTemplateIDAmbiguity is not resolved inside noexcept


The following code produces an AST containing a CPPASTTemplateIDAmbiguity and I’m not sure if this is should happen or not.

#include <type_traits>

template<typename T>
struct Foo {
Foo() noexcept(std::is_nothrow_default_constructible<T>::value) {}

int main() {
Foo<int> foo { };

CPPASTFunctionDeclarator.noexceptExpression is of type CPPASTTemplateIDAmbiguity even after ASTTranslationUnit.resolveAmbiguities() has been called. Is this behavior expected or not?

I’ve done some research and found the following:

If int instead of T is used in the template-id (std::is_nothrow_default_constructible<int>::value) then a CPPASTIdExpression is created and set as CPPASTFunctionDeclarator.noexceptExpression. As I expect it.

CPPASTTemplateIDAmbiguity.doResolveAmbiguity(ASTVisitor) is called which then calls owner.replace(nodeToReplace, _expression_).
owner is the CPPASTFunctionDeclarator, nodeToReplace=CPPASTTemplateIDAmbiguity and _expression_=CPPASTIdExpression which seems to be correct. 
But the CPPASTFunctionDeclarator.replace(IASTNode, IASTNode) that is called checks if a parameter is replaced. Which is not the case here, so nothing is replaced and assert false; is executed. This method only supports the replacement of parameters but not the noexceptExpression.
If run with the JVM -ea flag it even throws an AssertionError because replace should always find a parameter node to replace. So I guess this is a bug.

I found this while trying to copy the CPPASTTemplateDeclaration for std::vector in libstdc++ and most (all?) ambiguous nodes throw an UnsupportedOperationException on copy. The vector implementation in libstdc++ contains exactly this vector ctor with noexcept with and after C++11.

If it’s really a bug I will report it later. But I’ll wait a bit. I’m still new to CDT and maybe I’m doing something wrong.


_______________________________________________ cdt-dev mailing list cdt-dev@xxxxxxxxxxx To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top