Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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.


Back to the top