[cfe-dev] Detect if a CXXConstructExpr is implicit
Keane, Erich via cfe-dev
cfe-dev at lists.llvm.org
Tue Feb 12 08:50:48 PST 2019
If you look at the AST for the record decl, there is a bunch of flags in the DefinitionData of interest:
|-CXXRecordDecl <line:1:1, line:6:1> line:1:7 referenced class A
|definition
| |-DefinitionData empty standard_layout has_user_declared_ctor
| |can_const_default_init
| | |-DefaultConstructor exists non_trivial user_provided
| | |defaulted_is_constexpr -CopyConstructor non_trivial user_declared
| | |has_const_param implicit_has_const_param -MoveConstructor
| | |-CopyAssignment trivial has_const_param needs_implicit
| | |implicit_has_const_param -MoveAssignment
See "user_provided" and "user_declared". I'm not sure what the difference between those two is however.
-----Original Message-----
From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of Loïc Joly via cfe-dev
Sent: Tuesday, February 12, 2019 8:44 AM
To: cfe-dev at lists.llvm.org
Subject: [cfe-dev] Detect if a CXXConstructExpr is implicit
In the following code:
https://godbolt.org/z/czpHOf
classA{
public:
A();
A(A const&a);
A(inti);
};
voidf(A a);
voidg() {
A a;
f(a); // 1
f(2); // 2
}
The generated AST contains nodes about object construction that are implicit (the copy constructor for 1, the conversion then the copy constructor for 2).
|-CallExpr <line:12:5, col:8> 'void'
| |-ImplicitCastExpr <col:5> 'void (*)(A)' <FunctionToPointerDecay>
| | `-DeclRefExpr <col:5> 'void (A)' lvalue Function 0x55c42589b208 'f' 'void (A)'
| `-CXXConstructExpr <col:7> 'A' 'void (const A &)'
| `-ImplicitCastExpr <col:7> 'const A' lvalue <NoOp>
| `-DeclRefExpr <col:7> 'A' lvalue Var 0x55c42589b3c8 'a' 'A'
`-ExprWithCleanups <line:13:5, col:8> 'void'
`-CallExpr <col:5, col:8> 'void'
|-ImplicitCastExpr <col:5> 'void (*)(A)' <FunctionToPointerDecay>
| `-DeclRefExpr <col:5> 'void (A)' lvalue Function
0x55c42589b208 'f' 'void (A)'
`-CXXConstructExpr <col:7> 'A' 'void (const A &)' elidable
`-MaterializeTemporaryExpr <col:7> 'const A' lvalue
`-ImplicitCastExpr <col:7> 'const A' <NoOp>
`-ImplicitCastExpr <col:7> 'A' <ConstructorConversion>
`-CXXConstructExpr <col:7> 'A' 'void (int)'
`-IntegerLiteral <col:7> 'int' 2
Do you know if there is a way to detect that these constructions are implicit (as opposed to constructions written as the type name followed by initialization?)
Thank you!
---
Loïc Joly
_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list