Commit Graph

3052 Commits

Author SHA1 Message Date
Jakub Jelinek
34e0841e21 Export build_stub_type and use it in reflect.cc where needed. 2026-01-14 11:01:05 -05:00
Jakub Jelinek
c6b5bd5100 Add direct_base_parent{_binfo,} helpers. 2026-01-14 11:01:05 -05:00
Marek Polacek
39c4c97dbf Rework consteval-only type cheking
Introduce check_consteval_only_fn and call it in grokfndecl
and instantiate_body.  Also make std::meta::exception special
member functions consteval.

I couldn't use check_consteval_only_fn in tsubst_function_decl
due to too many failures in libstdc++.
2026-01-14 11:01:02 -05:00
Jakub Jelinek
0c83e5ecec Fix up splice_p default for finish_class_member_access_expr. 2026-01-14 11:00:59 -05:00
Marek Polacek
375d86bcff Amend SPLICE_EXPR_EXPRESSION_P comment 2026-01-14 11:00:58 -05:00
Marek Polacek
e7167f7f51 Move static_cast into REFLECT_EXPR_KIND
And add SET_REFLECT_EXPR_KIND
2026-01-14 11:00:56 -05:00
Marek Polacek
40df270f24 Mark annotation_p as pure 2026-01-14 11:00:53 -05:00
Marek Polacek
44f75bb235 check_splice_expr cleanups 2026-01-14 11:00:53 -05:00
Marek Polacek
c4ffa609e5 Introduce decl_in_std_meta_p
...and remove DECL_NAMESPACE_STD_META_P.
2026-01-14 11:00:51 -05:00
Jakub Jelinek
18d0b9ec29 Some tweaks from patch review: https://gcc.gnu.org/pipermail/gcc-patches/2025-November/702228.html 2026-01-14 11:00:44 -05:00
Jakub Jelinek
a95408e2c5 Introduce REFLECT_ANNOTATION. 2026-01-14 11:00:38 -05:00
Jakub Jelinek
f24f42a8fa Attempt to implement a mangling scheme for https://github.com/itanium-cxx-abi/cxx-abi/issues/208
This adds to the Itanium mangling's <builtin-type> non-terminal:
                 ::= Dm # std::meta::info (i.e., decltype(^^int))
and to <expr-primary>
		 ::= L Dm <value reflection> E   # C++26 reflection value
and new non-terminal:
  <reflection> ::= nu                                 # null reflection
               ::= vl <expression>                    # value
               ::= ob <expression>                    # object
               ::= vr <variable name>                 # variable
               ::= sb <sb name>                       # structured binding
               ::= fn <function encoding>             # function
               ::= pa [ <nonnegative number> ] _ <encoding>  # function parameter
               ::= en <prefix> <unqualified-name>     # enumerator
               ::= an [ <nonnegative number> ] _      # annotation
               ::= ta <alias prefix>                  # type alias
               ::= ty <type>                          # type
               ::= dm <prefix> <unqualified-name>     # non-static data member
               ::= un <prefix> [ <nonnegative number> ] _ # unnamed bit-field
               ::= ct [ <prefix> ] <unqualified-name> # class template
               ::= ft [ <prefix> ] <unqualified-name> # function template
               ::= vt [ <prefix> ] <unqualified-name> # variable template
               ::= at [ <prefix> ] <unqualified-name> # alias template
               ::= co [ <prefix> ] <unqualified-name> # concept
               ::= na [ <prefix> ] <unqualified-name> # namespace alias
               ::= ns [ <prefix> ] <unqualified-name> # namespace
               ::= ng                                 # ^^::
               ::= ba [ <nonnegative number> ] _ <type> # direct base class relationship
               ::= ds <type> _ [ <unqualified-name> ] _
                   [ <alignment number> ] _ [ <bit-width number> ] _
                   [ n ]                             # data member description

The first 2 letters are based on which [meta.reflection.queries] function
is true on the reflection (nu is for std::meta::info{}, then for
reflection satisfying is_value, is_object, is_variable, is_structured_binding,
is_function, is_function_parameter, is_enumerator, is_annotation, is_type_alias,
is_type, is_nonstatic_data_member, is_bit_field && !has_identifier,
is_class_template, is_function_template, is_variable_template, is_alias_template,
is_concept, is_namespace_alias, is_namespace (except for ^^::), ^^::,
is_base and is_data_member_spec.
Function parameter reflections are encoded as Nth parameter of <encoding>,
where just _ is 1st, 0_ 2nd, 1_ 3rd etc.  Annotation reflections are always
TU-local, so are mangled just as some implementation-defined non-negative number
unique to each annotation in the translation unit (_ is for 1st, 0_ 2nd, 1_ 3rd
etc.).  Reflections of unnamed bit-fields are mangled as Nth unnamed bit-field
in a particular class represented by <prefix>.  Reflections of direct base
class relationship are mangled as Nth direct base of <type>.  Reflections of
data member descriptions are mangled as the elements of the quintuple separated
with _ characters, required type, optional identifier, optional alignment,
optional bit-width and optional character n if .no_unique_address is true.

Something that should be still specified is what mangling to use
for constructors and destructors, the patch currently uses C4 and D4 (which aren't
in the Itanium mangling base grammar, but there is nothing about the original
cdtors before they get cloned).
2026-01-14 11:00:36 -05:00
Jakub Jelinek
686ef16550 Implement the throw part of P3914R0 US 130-193 resolution.
In particular that violated Mandates, or missing ::type or ::value
results in throw of std::meta::exception.
2026-01-14 11:00:35 -05:00
Jakub Jelinek
ec1a1aded9 Implement [expr.const]/10.28 and [expr.const]/31 and increase define_aggregate test coverage. 2026-01-14 11:00:29 -05:00
Marek Polacek
417946bf4f Fix consteval-only smuggling detection
It was in the wrong spot, causing bogus "conversion from consteval-only
type" errors when using std::vector<info> and so on.
2026-01-14 10:58:51 -05:00
Jakub Jelinek
5ab0f135e5 Fix ordering of annotations on decls, some progress on annotations on direct base relationship.
Plus fix up diagnostics of invalid annotations on namespaces.

Still needs tests for ordering of annotations on namespaces, finish
direct base relationship annotations, and guess test ordering of
annotations on all kinds of stuff, in templates etc.
2026-01-14 10:58:50 -05:00
Jakub Jelinek
bc0212bab0 Some fixes for members_of on namespaces. 2026-01-14 10:58:48 -05:00
Jakub Jelinek
d2569258b0 Implement std::meta::{{bases,subobjects}_of,has_inaccessible_{bases,subobjects}}. 2026-01-14 10:58:46 -05:00
Marek Polacek
82732e7d22 Implement std::meta::constant_of
Unfortunately this needed other changes.  I need to have a function to
check if a splice-expression is valid so I had to factor out some code
out to check_splice_expr.  Then I realized pt.cc needs to know in which
context the original SPLICE_EXPR was found so that needed two new flags.

compare_reflections has a new hack, but this should be fixed rather soon
on trunk and then the hack can go after a rebase.

I discovered a new ICE, fixed, and tested in crash13.C.

Annotations are to be done, but it should be easy.
2026-01-14 10:58:46 -05:00
Jakub Jelinek
09f2c4896f Implement std::meta::access_context. 2026-01-14 10:58:44 -05:00
Marek Polacek
38bfe3710c Implement std::meta::is_value 2026-01-14 10:58:43 -05:00
Marek Polacek
b964766000 Fix crash when invoking metafn through fnptr 2026-01-14 10:58:42 -05:00
Jakub Jelinek
6032d7391c Implement std::meta::define_aggregate.
Also, fix up type_of for bit-fields.  And add some tests to data_member_spec1
for invalid identifiers.
2026-01-14 10:58:41 -05:00
Marek Polacek
8778cf887e Implement std::meta::tuple_{size,element} 2026-01-14 10:58:41 -05:00
Jakub Jelinek
edb051f3ba Implement std::meta::{data_member_spec,is_data_member_spec}. 2026-01-14 10:58:40 -05:00
Jakub Jelinek
2e8b6092f5 Implement std::meta::has_identifier. 2026-01-14 10:58:38 -05:00
Jakub Jelinek
371aa870b9 Implement std::meta::has_default_argument. 2026-01-14 10:58:38 -05:00
Jakub Jelinek
01ed66c44e Implement std::meta::operator_of and std::meta::{,u8}_symbol_of. 2026-01-14 10:58:33 -05:00
Jakub Jelinek
73c2aa61d5 Implement std::is_string_literal.
This isn't in std::meta namespace, so I've used a FE builtin to implement
it instead of process_metafunction.

Also, I think using vector; in std::meta namespace is wrong, the standard
doesn't mention it and we don't want people to use std::meta::vector<int>
in their code.
2026-01-14 10:58:33 -05:00
Marek Polacek
dcf35dc8f8 Implement std::meta::is_object
This also fixes is_function_parameter and introduces REFLECT_EXPR_KIND
because sometimes the handle isn't enough to distinguish different
categories of reflections.  For example, a PARM_DECL handle can be both
is_variable or is_function_parameter, but we can't know which one it is
just by looking at the PARM_DECL.
2026-01-14 10:58:32 -05:00
Jakub Jelinek
0510df7079 Implement std::meta::type_of (and has-type exposition only predicate).
Some cases aren't done yet because they depend on the implementation
of other metafunctions and decision how those reflections will be
represented.

I had to change process_metafunction/get_info, because some tests
in the new testcase were failing otherwise.  cxx_constant_value
is a wrong way to evaluate arguments of metafunction, they need to
be evaluated in the same constant expression context as the rest,
they can also throw, break, continue, return (the latter three only
when using GNU statement expressions), and e.g. could perform heap
allocation if something during the same evaluation later on deletes
those etc.
In particular, e.g. type_of (reflect_constant (42)) didn't work,
because it attempted to constant evaluate reflect_constant separately.
2026-01-14 10:58:31 -05:00
Marek Polacek
35f672aabd Implement std::meta::reflect_constant
Needs *much* more testing still.
2026-01-14 10:58:30 -05:00
Jakub Jelinek
48fe04f975 Implement is_enumerable_type.
This is harder because we clear ENUM_IS_OPAQUE flag when parsing
the { of the enum specifier and so during parsing (or instantiation)
of the enumerator values we don't know if it is still being defined
or not (and COMPLETE_TYPE_P doesn't work due to enums with underlying
type).
2026-01-14 10:58:29 -05:00
Jakub Jelinek
caf633b275 Parsing part of C++ 26 P3394R4 - Annotations for Reflection 2026-01-14 10:56:35 -05:00
Marek Polacek
a88faed5af Implement std::meta::exception 2026-01-14 10:56:34 -05:00
Marek Polacek
0902fb45c0 Fix last merge 2026-01-14 10:56:34 -05:00
Marek Polacek
5e02a97a92 Implement std::meta::parameters_of
This involved adding vector<info> & co.  Only lightly tested.
2026-01-14 10:56:33 -05:00
Marek Polacek
9d660ab78b Verify better what splice-expression expands to
This introduces SPLICE_EXPR_EXPRESSION_P to distinguish between
a splice-expression and splice-specifier.
2026-01-14 10:56:28 -05:00
Marek Polacek
751581fb80 Check returning consteval-only expressions 2026-01-14 10:56:27 -05:00
Marek Polacek
213ac6366f Detect using consteval-only vars without constexpr
We didn't detect namespace-scope vars of consteval-only type
without constexpr/constinit.  Fixed by calling check_out_of_consteval_use
in cp_finish_decl.

Also remove consteval_only_var_p and consteval_only_type_p in
favor of consteval_only_p.

Sadly,
  info baz () { return ^^int; }
still ICEs.  To be fixed.
2026-01-14 10:56:26 -05:00
Marek Polacek
e797f14b8f Partial substitution of a SPLICE_SCOPE
Introduce & use dependent_splice_p, make_splice_scope, and
tsubst_splice_scope which makes for a nice cleanup.
2026-01-14 10:56:25 -05:00
Marek Polacek
595c31fcbc Implement [class.access.base]/5
This allows member access through a splice of a private member.
2026-01-14 10:56:24 -05:00
Marek Polacek
4245417eff Detect invalid splice-{scope,type}-specifiers 2026-01-14 10:56:24 -05:00
Marek Polacek
919c2a7eae Detect consteval-only smuggling
This has not been tested very well.
2026-01-14 10:56:22 -05:00
Marek Polacek
e7bebd7208 Detect taking the reflection of a using-declarator
As per [expr.reflect]/5.
2026-01-14 10:56:22 -05:00
Marek Polacek
49ddf87293 Detect more consteval-only exprs used outside mce ctx 2026-01-14 10:56:19 -05:00
Marek Polacek
d042111da0 Dependent namespaces
See [temp.dep.namespace]
2026-01-14 10:56:18 -05:00
Marek Polacek
ad1d692a2d Dependent scopes, add SPLICE_SCOPE 2026-01-14 10:56:18 -05:00
Marek Polacek
c2bb10fe26 Fix consteval_only_var_p 2026-01-14 10:56:16 -05:00
Marek Polacek
f20dcb9ef7 Strip injected-class-names 2026-01-14 10:56:16 -05:00