[cfe-users] Implicit or explicit public inheritance in the AST

David Blaikie via cfe-users cfe-users at lists.llvm.org
Mon Jun 8 15:55:11 PDT 2020


Looks like comparing getAccessSpecifierAsWritten with
getAccessSpecifier might help:
https://clang.llvm.org/doxygen/classclang_1_1CXXBaseSpecifier.html#a6abcd6d5d707f4cab88bab1fc916bfad

On Mon, Jun 8, 2020 at 1:09 PM Csaba Raduly via cfe-users
<cfe-users at lists.llvm.org> wrote:
>
> Hi all,
>
> If I run `clang++ -std=c++17 -Xclang -ast-dump` on the following code:
>
> struct B {};
>
> struct D1 : B {};
>
> struct D2 : public B {};
>
> the output is
>
> |-CXXRecordDecl 0x8000bdd48 <kg.cpp:1:1, col:11> col:8 referenced struct B definition
> | |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
> | | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
> | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
> | | |-MoveConstructor exists simple trivial needs_implicit
> | | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
> | | |-MoveAssignment exists simple trivial needs_implicit
> | | `-Destructor simple irrelevant trivial needs_implicit
> | `-CXXRecordDecl 0x8000bde58 <col:1, col:8> col:8 implicit struct B
> |-CXXRecordDecl 0x8000bdef8 <line:3:1, col:16> col:8 struct D1 definition
> | |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
> | | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
> | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
> | | |-MoveConstructor exists simple trivial needs_implicit
> | | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
> | | |-MoveAssignment exists simple trivial needs_implicit
> | | `-Destructor simple irrelevant trivial needs_implicit
> | |-public 'B'
> | `-CXXRecordDecl 0x80015c878 <col:1, col:8> col:8 implicit struct D1
> `-CXXRecordDecl 0x80015c918 <line:5:1, col:23> col:8 struct D2 definition
>   |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
>   | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
>   | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
>   | |-MoveConstructor exists simple trivial needs_implicit
>   | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
>   | |-MoveAssignment exists simple trivial needs_implicit
>   | `-Destructor simple irrelevant trivial needs_implicit
>   |-public 'B'
>   `-CXXRecordDecl 0x80015ca68 <col:1, col:8> col:8 implicit struct D2
> I can see no difference between the CXXRecordDecl for D1 and D2. Is there a way to tell, when visiting the AST, whether the inheritance of the derived class was specified implicitly or explicitly? (Hopefully yes, just not visible in the output of ast-dump).
>
>
> Csaba
> Sent from my 12-core Windows machine, using Gmail.
> --
> You can get very substantial performance improvements
> by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
> So if you're looking for a completely portable, 100% standards-conformant way
> to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


More information about the cfe-users mailing list