Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mangling for constrained templates #24

Open
zygoloid opened this issue Jul 26, 2017 · 31 comments
Open

mangling for constrained templates #24

zygoloid opened this issue Jul 26, 2017 · 31 comments
Labels
pending committee feedback The issue is blocked waiting for a response from the committee.

Comments

@zygoloid
Copy link
Contributor

zygoloid commented Jul 26, 2017

p0734r0 added new forms of overloadable declaration that we need to mangle. For instance, we now need to distinguish:

template<typename T> concept A = ...
template<typename T> concept B = ...
template<A T> void f(T); // f1
template<B T> void f(T); // f2
template<typename T> requires A<T> void g(T); // g1
template<typename T> requires B<T> void g(T); // g2

It is permissible (but not necessary) for the mangling of f1 and g1 to be the same (other than the name).

(There are also requires-clauses on non-template functions, but I don't believe there is any need to mangle those since at most one such function can have its requires-clause evaluate to true, and the rest are never emitted.)

As a general model, I suggest we include "extra information" about a template-parameter (for a function template -- we don't need this for non-overloadable templates) as a prefix on the template-arg mangling. (We should also consider extending this to the case where the the template parameter is a template template parameter and the template argument does not have an identical template-parameter-list, to handle the case described in http://sourcerytools.com/pipermail/cxx-abi-dev/2014-December/002791.html)

I suggest we affix the constraint expression from the requires-clause (if any) to the template-args, and do not perform any expansion or canonicalization of the as-written form of the template declaration. Strawman mangling suggestion:

<template-arg> ::= C <concept name> <template-arg>
<template-args> ::= I <template-arg>+ Q <requires-clause expr> E

Example:

template<A T, B U> requires C<T, U> void f();
f<int, 3>(); // _Z1fIC1AiC1BLi3EQ1CIT_T0_EEvv
@rjmccall
Copy link
Collaborator

Is your statement about non-template functions true in the case that not all such functions are declared in the same translation unit? Or is that impossible because such functions must be defined within templates?

@rjmccall
Copy link
Collaborator

rjmccall commented Jul 26, 2017

Does the standard consider these to be different declarations for the purposes of the ODR?

  template <A T> void foo();
  template <class T> requires A<T> void foo();

Oh, I see you answered that: it's unspecified.

I feel like it would be responsible for us to do some minimal canonicalization here.

@thiagomacieira
Copy link

thiagomacieira commented Jul 26, 2017

Similarly, does it consider these two to be two different functions, even if both concepts are exactly the same (same requirements, literally)?

  template<typename T> concept A = ...
  template<typename T> concept B = ...
  template<A T> void f(T); // f1
  template<B T> void f(T); // f2

If that is the case, trying to call f with any argument that matches the concepts is an ambiguous overload, correct?

But if I split the two in two different translation units, could I call two different functions and not violate ODR?

And what happens if two different TUs have differing concepts that have the same name? ODR violation?

@daveedvdv
Copy link

daveedvdv commented Jul 26, 2017 via email

@daveedvdv
Copy link

daveedvdv commented Jul 26, 2017 via email

@thiagomacieira
Copy link

Please note that your reply removed everything between the angle brackets, so you removed important information. But to be clear, I'm asking:
a.cpp:

template<typename T> concept A = { something here; };
template<A T> void f(T) {}

b.cpp:

template<typename T> concept B = { something here; };
template<B T> void f(T) {}

Specifically, aside from the change of A to B, the rest is exactly the same, literally so for the concept declaration. In other words: what defines a concept: the name or the requirements?

And as a corollary, in c.cpp:

template<typename T> concept A = { something very different here; };
template<A T> void f(T) {}

If concepts are identified by name, then the above is must be ODR violation (no diagnostic required). Is this understanding correct?

@daveedvdv
Copy link

daveedvdv commented Jul 26, 2017 via email

@thiagomacieira
Copy link

I believe concepts have linkage, and therefore, yes, that would be an ODR violation (even without the declaration of f).

If they have linkage, we need to mangle that too.

Why do they have to have linkage?

@rjmccall
Copy link
Collaborator

It looks like concepts with the same name are required to be defined the same way in different translation units. I don't know if there's a way of giving a concept "linkage" per se.

@thiagomacieira
Copy link

Something like IFNDR then.

@rjmccall
Copy link
Collaborator

It looks like Daveed's statement is correct: two template-heads (template parameter list + requires clause) are equivalent only if they are written in exactly the same way, but they are functionally equivalent if they accept the same set of template arguments. So we are allowed but not required to treat those as distinct templates. (Exactly like Richard said.)

@rjmccall
Copy link
Collaborator

I feel like people would probably be surprised by trivial differences breaking ABI, but on the other that's already true of function templates, and it mostly doesn't matter because:

  • depending on function pointer equality is extremely rare (and foolish) and
  • depending on the address/uniqueness of a static variable within a function template is rare, albeit less so (and most justifiable) than depending on function pointer equality.

So Richard's idea of not doing any canonicalization is appealing. But if anything about concepts requires us to mangle template-heads for something besides identifying a function template, we'll be in more trouble.

@tahonermann
Copy link
Contributor

(There are also requires-clauses on non-template functions, but I don't believe there is any need to mangle those since at most one such function can have its requires-clause evaluate to true, and the rest are never emitted.)

For tool vendors such as Synopsys/Coverity, having different mangled names for each distinct declaration is useful, even if only one of them can ever be "activated" within a TU. However, this is a niche requirement and we can resort to vendor extensions (as we have in other cases such as "conflicting" inline friend function definitions in different class templates) if including mangling would be at all problematic for other implementors.

@zygoloid
Copy link
Contributor Author

zygoloid commented Jul 26, 2017

Is your statement about non-template functions true in the case that not all such functions are declared in the same translation unit?

The wording in this area is unclear, and we have an open issue on it. Example:

// translation unit 1
struct A {};
struct B;
template<typename T> concept bool Complete = requires { sizeof(T); };
inline void f() requires Complete<A> {};
inline void f() requires Complete<B> {};
// translation unit 2
struct A;
struct B {};
template<typename T> concept bool Complete = requires { sizeof(T); };
inline void f() requires Complete<A> {};
inline void f() requires Complete<B> {};

It's not clear whether this program is valid, or (if valid) what it means. And the same situation can arise even within a TU:

struct A;
struct B;
template<typename T> concept bool Complete = requires { sizeof(T); };
inline void f() requires !Complete<A> || Complete<B> {}; // #1
inline void f() requires Complete<A> && !Complete<B> {}; // #2
void g() { f(); } // calls #1
struct A {};
void h() { f(); } // calls #2
struct B {};
void i() { f(); } // calls #1

Or is that impossible because such functions must be defined within templates?

There is no such requirement... yet.

If nothing else, I'd say the underspecification in this area and the likelihood of changes suggests that we shouldn't commit to a mangling for this construct yet.

@rjmccall
Copy link
Collaborator

Interesting, alright.

@rjmccall rjmccall added the pending committee feedback The issue is blocked waiting for a response from the committee. label Sep 10, 2017
@saarraz
Copy link

saarraz commented Jul 26, 2019

Hi, trying to bring this back to life now that we have a more final version of the language feature.
@zygoloid were the issues mentioned here addressed since?

Also, we're going to need some way to mangle requires-expressions (which should be less problematic, I believe?).

@rjmccall
Copy link
Collaborator

rjmccall commented Aug 3, 2019

It's not conceptually problematic, but the parameter clause does make it non-trivial to invent a mangling for.

@zygoloid
Copy link
Contributor Author

See also #47, in which I gave a suggestion for when to include a <template-param-decl> as part of a <template-arg> mangling, and #85, which defines <template-param-decl> for use in <lambda-sig>.

@dfrib
Copy link

dfrib commented Oct 5, 2021

(There are also requires-clauses on non-template functions, but I don't believe there is any need to mangle those since at most one such function can have its requires-clause evaluate to true, and the rest are never emitted.)

As per US115 of P2103R0 hidden non-template friends may also use requires-clauses:

struct Base {};

template<int N>
struct S : public Base {
    friend int foo(Base&) requires (N == 1) { return 1; }
    friend int foo(Base&) requires (N == 2) { return 3; }
};

int main() {
    S<1> s1{};
    S<2> s2{};  // GCC & MSVC: re-definition error of 'foo'
    auto const foo1 = foo(s1); // #1
    auto const foo2 = foo(s2); // Clang error: definition with same mangled name as another definition
} 

On a tangent: is it well-specified whether such friends are late-instantiated only for the enclosing class template specializations for which its requires-clause is fulfilled? Afaict all three compilers are wrong here, but is the program well-formed or ill-formed due to an ambiguity at #1?

@rjmccall
Copy link
Collaborator

rjmccall commented Oct 5, 2021

Well, that's an exciting special case.

Such a constrained friend function or function template declaration does not declare the same function or function template as a declaration in any other scope.

That's fairly clear: GCC and MSVC are wrong because these are not redeclarations, and Clang is wrong because this is well-formed and we aren't allowed to reject it because of a mangling conflict. The only viable implementation path I can see, given that nothing in the standard prevents these friend declarations from otherwise matching perfectly in signatures and requires-clauses, is to mangle the declaring class for these friends. Note that mangling the requires-clause is not sufficient: we cannot rely on ambiguity to force there to only be a single friend declaration with satisfied constraints because the instantiations could be split between TUs.

Mangling the declaring class shouldn't impose a significant symbol size penalty because in non-perverse code the declaring class will be mentioned in the function signature, so substitution will apply. Unfortunately, I don't think we can turn that into a constraint which would let us avoid including the mangling.

On a tangent: is it well-specified whether such friends are late-instantiated only for the enclosing class template specializations for which its requires-clause is fulfilled?

There doesn't seem to be a concept in the standard of only instantiating functions whose requires-clauses are satisfied; such functions always exist and are weeded out as non-viable during overload resolution. But no, the current wording seems to just not cover what happens when instantiating a friend function:

The type-constraints and requires-clause of a template specialization or member function are not instantiated along with the specialization or function itself, even for a member function of a local class; substitution into the atomic constraints formed from them is instead performed as specified in [temp.constr.decl] and [temp.constr.atomic] when determining whether the constraints are satisfied or as specified in [temp.constr.decl] when comparing declarations.

Non-template friend functions are neither template specializations nor members.

Afaict all three compilers are wrong here, but is the program well-formed or ill-formed due to an ambiguity at #1?

I don't see why there would be an ambiguity.

Do you have any interest in writing this up? We'll need to pick some way to mangle something as a friend from a particular declaring class, and it can't just be the normal member mangling.

CC @zygoloid

@zygoloid
Copy link
Contributor Author

zygoloid commented Oct 5, 2021

The only viable implementation path I can see, given that nothing in the standard prevents these friend declarations from otherwise matching perfectly in signatures and requires-clauses, is to mangle the declaring class for these friends.

That's the implementation strategy we had in mind when this was discussed in committee. I agree that we can't use the normal member mangling here, because a friend and a member can have the same signature.

I think the mangling needs the fully-qualified mangled name of the class and only a simple identifier for the function; it's not sufficient to mangle the fully-qualified name of the function and only a simple identifier for the class because the class could be a template specialization or a local class. So modeling the friend as if it were a member, with some disambiguator character(s) added to distinguish the cases, makes sense to me.

Perhaps we could allow a marker for this prior to the final <unqualified-name> in a <nested-name>? The mangling grammar doesn't make that convenient to express, but I think it could be something like:

-    <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
+    <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> [F] <unqualified-name> E

...

     <template-prefix> ::= <template unqualified-name>           # global template
-                      ::= <prefix> <template unqualified-name>  # nested template
+                      ::= <prefix> [F] <template unqualified-name>  # nested template

@rjmccall
Copy link
Collaborator

rjmccall commented Oct 6, 2021

I think that should work, since the namespace of a friend function definition is always derivable from the class. And I like that it maintains a common prefix with true class members.

@dfrib
Copy link

dfrib commented Feb 28, 2022

Do you have any interest in writing this up? We'll need to pick some way to mangle something as a friend from a particular declaring class, and it can't just be the normal member mangling.

Sorry for the late reply, I forgot about this.

I would be happy to, as an instructive ABI journey, start from @zygoloid's proposal above and submit a PR. If so, should I open an separate issue for this isolated case?

@erichkeane
Copy link

Was this ever merged into the ABI? was 'F' chosen as the differentiator here?

Is the solution here to ALWAYS mangle 'friend' functions as a member function? Do we fear that this is an ABI break (since the name is changing?), or is it that the definition is 'inline' to the class, that the name change cannot break ABI?

@Arcoth
Copy link

Arcoth commented Jan 22, 2023

(There are also requires-clauses on non-template functions, but I don't believe there is any need to mangle those since at most one such function can have its requires-clause evaluate to true, and the rest are never emitted.)

Why at most one? What about

    template<int I> concept C = true;

    template <typename T = int> struct A {
        int f() requires C<42> { return 0; }
        long f() requires true {return 0; }
    };
    
    int x = (A<>{}.*((int(A<>::*)())&A<>::f))();
    
    int y = (A<>{}.*((long(A<>::*)())&A<>::f))();

I don't see this being prohibited by current wording. Also, the "at most one" part is contradicted by e.g. https://eel.is/c++draft/temp.spec#temp.inst-example-10. Clearly the idea was that such templated functions would not be distinguishable during overload resolution, so only one could be instantiated per enclosing specialization, but if we distinguish via the return type which is not mangled AFAICS, the problem returns.

@zygoloid
Copy link
Contributor Author

(There are also requires-clauses on non-template functions, but I don't believe there is any need to mangle those since at most one such function can have its requires-clause evaluate to true, and the rest are never emitted.)

Why at most one?

I'm not sure whether the rules here changed between when I wrote my initial comment and the final C++20 standard, but in any case, I agree; we do need to mangle trailing requires clauses for non-template functions; they are part of the signature.

@zygoloid
Copy link
Contributor Author

zygoloid commented Mar 31, 2023

Use of C is unwise due to collisions with complex types. Revised suggestion follows; this is intended to replace prior suggestions on this issue, and augment the rules proposed in #47.

Type constraints are mangled following the source syntax:

  • <type-constraint> ::= <name>

A type constraint C or C<> is mangled as the name of the concept C. A type constraint C<Args> with non-empty Args is mangled as the name of the hypothetical template specialization C<Args>, even though it would result in a satisfaction check for C<T, Args> for some T. For example, 12IsBiggerThanIiE or N3Lib11IsContainerIiEE.

  • <template-param-decl> ::= Tk <type-constraint> # constrained type parameter

Constrained type template parameters use a new mangling instead of Ty. This applies not only in the cases where we currently mangle template parameters (for example, in the signature of a lambda), but also in #47 step 3: the natural template parameter for any template argument is always unconstrained, so this also applies in every <template-arg> where the parameter is constrained and the template is overloadable:

template<C T> void f() {}
// _Z1fITk1CiEvv
template void f<int>();
  • <template-param-decl> ::= Tt <template-param-decl>* [Q <constraint-expression>] E

Template template parameters can have requires-clauses, and function templates can be overloaded on the requires-clauses of their template template parameters, so the requires-clause is included in the mangling of the template template parameter.

When constrained auto is used to declare an abbreviated function template, the language rules permit the function template to be redeclared with an explicit template parameter, so the abbreviated function template is rewritten to the non-abbreviated form prior to mangling:

void f(C auto) {}
// _Z1fITk1CiEvT_
template void f<int>(int);

When a constrained placeholder type appears in contexts where it is not rewritten to a template parameter, it is mangled with its constraint, instead of with the Da / Dc mangling:

  • <type> ::= Dk <type-constraint> # constrained auto
  • <type> ::= DK <type-constraint> # constrained decltype(auto)

For example:

template<C auto N> void f() {}
// _Z1fITnDk1CLi5EEvv
template void f<5>();

template<typename T> void g(decltype(new C auto(T())) x) {}
// _Z1gIiEvDTnw_Dk1CpicvT__EEE
template void g<int>(int*);

A requires-clause that follows a template-parameter-list is appended to the corresponding <template-args> when mangling an overloadable template, as defined in #47.

  • <template-args> ::= I <template-arg>+ [Q <constraint-expression>] E

A trailing requires-clause is mangled as a suffix on the encoding of a function:

  • <encoding> ::= <function name> <bare-function-type> [Q <constraint-expression>]

This applies to all cases where a trailing requires-clause is permitted: function template specializations, members of templated classes, and friends of templated classes.

Non-template friend function declarations with trailing requires-clauses and friend function templates whose constraints involve enclosing template parameters have special linkage rules: they are distinct from declarations in other scopes, and instead behave like class members for linkage purposes. We call these member-like constrained friends. Member-like constrained friends are mangled as if they were class member functions, with an F preceding their unqualified name:

  • <unqualified-name> ::= F <source-name> # member-like constrained friend
  • <unqualified-name> ::= F <operator-name> # member-like constrained friend

Constrained lambdas have two places where requires-clauses can appear: after the template parameter list, and after the function parameter list. Both are mangled, in lexical order:

  • <lambda-sig> ::= <template-param-decl>* [Q <early constraint-expression>] <parameter type>+ [Q <late constraint-expression>]

Concept-ids are always mangled as unresolved-names, never as L_Z<encoding>E, even when none of the template arguments is instantiation-dependent. We can't use <encoding> when arguments are instantiation-dependent, because T_ references within an <encoding> never refer to enclosing parameters. (But see #38 for a pre-existing issue with unresolved-names.)

Substitution is never performed into <constraint-expression>s before they are mangled, so they can refer to all levels of enclosing template parameters. In a <constraint-expression>, T[<n>]_ refers to the outermost enclosing template parameter list (even if it belongs to an enclosing class template specialization), TL<n>__ refers to the next innermost level, and so on. A <constraint-expression> is otherwise mangled the same as any other <expression>.

  • <constraint-expression> ::= <expression>

@zygoloid
Copy link
Contributor Author

zygoloid commented Apr 3, 2023

We also need to mangle requires-expressions. Suggestion:

  • <expression> ::= rq <requirement>+ E # requires { ... }
  • <expression> ::= rQ <bare-function-type> _ <requirement>+ E # requires (...) { ... }

Within an rQ mangling, an extra depth of <function-param> is in scope, referring to the parameters of the requires-expression. Within an rq mangling, no extra depth of <function-param> is in scope, so fp_ refers to an enclosing function parameter. For consistency, an empty parameter list (requires () { ... } or requires (void) { ... }) is mangled as rQv_ not rQ_.

Requirements are mangled as follows:

  • <requirement> ::= X <expression> [N] [R <type-constraint>] # simple-requirement or compound-requirement
  • <requirement> ::= T <type> # type-requirement
  • <requirement> ::= Q <constraint-expression> # nested-requirement

The requirements expr; and {expr}; are functionally equivalent and have the same mangling. Expression requirements are suffixed with N for a noexcept requirement and with R <type-constraint> for a return-type-requirement.

TODO: requires-expressions can appear outside of constraint-expressions in the signature of a function or function template. It is unclear how to mangle these, as we may have performed substitution into only a subset of the requirements within them, and mangling the original expression can lead to collisions (eg, two friend templates declared in different classes can have requires-expressions in their signatures that look the same prior to substitution but different afterwards). This question is pending committee feedback.

@zygoloid
Copy link
Contributor Author

zygoloid commented Apr 6, 2023

@jicama @rjmccall @jhsedg Your thoughts on the above would be appreciated. It seems important that we settle an ABI for the C++20 additions fairly soon, given the increasing levels of adoption.

zygoloid added a commit to llvm/llvm-project that referenced this issue Sep 20, 2023
This implements proposals from:

- itanium-cxx-abi/cxx-abi#24: mangling for
  constraints, requires-clauses, requires-expressions.
- itanium-cxx-abi/cxx-abi#31: requires-clauses and
  template parameters in a lambda expression are mangled into the <lambda-sig>.
- itanium-cxx-abi/cxx-abi#47 (STEP 3): mangling for
  template argument is prefixed by mangling of template parameter declaration
  if it's not "obvious", for example because the template parameter is
  constrained (we already implemented STEP 1 and STEP 2).

This changes the manglings for a few cases:

- Functions and function templates with constraints.
- Function templates with template parameters with deduced types:
  `typename<auto N> void f();`
- Function templates with template template parameters where the argument has a
  different template-head:
  `template<template<typename...T>> void f(); f<std::vector>();`

In each case where a mangling changed, the change fixes a mangling collision.

Note that only function templates are affected, not class templates or variable
templates, and only new constructs (template parameters with deduced types,
constrained templates) and esoteric constructs (templates with template
template parameters with non-matching template template arguments, most of
which Clang still does not accept by default due to
`-frelaxed-template-template-args` not being enabled by default), so the risk
to ABI stability from this change is relatively low. Nonetheless,
`-fclang-abi-compat=17` can be used to restore the old manglings for cases
which we could successfully but incorrectly mangle before.

Fixes #48216, #49884, #61273

Reviewed By: erichkeane, #libc_abi

Differential Revision: https://reviews.llvm.org/D147655
@jicama
Copy link
Contributor

jicama commented Sep 25, 2023

When constrained auto is used to declare an abbreviated function template, the language rules permit the function template to be redeclared with an explicit template parameter, so the abbreviated function template is rewritten to the non-abbreviated form prior to mangling:

void f(C auto) {}
// _Z1fITk1CiEvT_
template void f<int>(int);

But they're not always equivalent because of the ordering of constraints in https://eel.is/c++draft/temp.constr.decl#3.3 specifying that the constraints from a requires-clause following the template parameters are checked before the constraints from type-constraints in the parameter-type-list. So e.g. here the ordering is important:

#include <type_traits>
template <class T> concept HasFoo = requires { typename T::foo; };
template <class T> concept NotVoid = !std::is_void<T>::value;
template <class T> struct A { T t; };
template <class T> requires NotVoid<T> void f(HasFoo auto);
template <class T, class U> void f(...);
template <class T> struct B { T t; };
template <class T, HasFoo U> requires NotVoid<T> void g(U);
template <class T, class U> void g(...);
int main()
{
  f<void,A<void>>(42); // OK, calls f(...)
  g<void,B<void>>(42); // concept checking causes bad instantiation of B<void>
}

I suppose we could do the rewriting you describe if there is no requires-clause on the template parameter list, but if there is, append the constraint-expressions from the parameter list to the requires-clause with && ?

My inclination would be to always mangle the combined constraint-expression from the above section rather than try to use a shorthand form for constrained type parameters, but I'm willing to go along with the Tk mangling for compactness.

@zygoloid
Copy link
Contributor Author

zygoloid commented Sep 25, 2023

When constrained auto is used to declare an abbreviated function template, the language rules permit the function template to be redeclared with an explicit template parameter, so the abbreviated function template is rewritten to the non-abbreviated form prior to mangling:

void f(C auto) {}
// _Z1fITk1CiEvT_
template void f<int>(int);

But they're not always equivalent because of the ordering of constraints in https://eel.is/c++draft/temp.constr.decl#3.3 specifying that the constraints from a requires-clause following the template parameters are checked before the constraints from type-constraints in the parameter-type-list.

The two declarations are always equivalent, per https://eel.is/c++draft/dcl.fct#22.sentence-2, so we are required to mangle them the same way. I agree that they have different behavior, but that's a CWG problem (mailed to the core reflector [edit: now CWG2802]) not an ABI problem. I think probably CWG1321 would specify the behavior here: we would use the associated constraints from the first declaration of the template (though CWG1321 predates concepts, and we seem to have somehow lost the normative changes there, and it's not clear how they'd work with modules...).

nstester pushed a commit to nstester/gcc that referenced this issue Dec 1, 2023
Per itanium-cxx-abi/cxx-abi#24 and
itanium-cxx-abi/cxx-abi#166

We need to mangle constraints to be able to distinguish between function
templates that only differ in constraints.  From the latter link, we want to
use the template parameter mangling previously specified for lambdas to also
make explicit the form of a template parameter where the argument is not a
"natural" fit for it, such as when the parameter is constrained or deduced.

I'm concerned about how the latter link changes the mangling for some C++98
and C++11 patterns, so I've limited template_parm_natural_p to avoid two
cases found by running the testsuite with -Wabi forced on:

template <class T, T V> T f() { return V; }
int main() { return f<int,42>(); }

template <int i> int max() { return i; }
template <int i, int j, int... rest> int max()
{
  int sub = max<j, rest...>();
  return i > sub ? i : sub;
}
int main() {  return max<1,2,3>(); }

A third C++11 pattern is changed by this patch:

template <template <typename...> class TT, typename... Ts> TT<Ts...> f();
template <typename> struct A { };
int main() { f<A,int>(); }

I aim to resolve these with the ABI committee before GCC 14.1.

We also need to resolve itanium-cxx-abi/cxx-abi#38
(mangling references to dependent template-ids where the name is fully
resolved) as references to concepts in std:: will consistently run into this
area.  This is why mangle-concepts1.C only refers to concepts in the global
namespace so far.

The library changes are to avoid trying to mangle builtins, which fails.

Demangler support and test coverage is not complete yet.

gcc/cp/ChangeLog:

	* cp-tree.h (TEMPLATE_ARGS_TYPE_CONSTRAINT_P): New.
	(get_concept_check_template): Declare.
	* constraint.cc (combine_constraint_expressions)
	(finish_shorthand_constraint): Use UNKNOWN_LOCATION.
	* pt.cc (convert_generic_types_to_packs): Likewise.
	* mangle.cc (write_constraint_expression)
	(write_tparms_constraints, write_type_constraint)
	(template_parm_natural_p, write_requirement)
	(write_requires_expr): New.
	(write_encoding): Mangle trailing requires-clause.
	(write_name): Pass parms to write_template_args.
	(write_template_param_decl): Factor out from...
	(write_closure_template_head): ...here.
	(write_template_args): Mangle non-natural parms
	and requires-clause.
	(write_expression): Handle REQUIRES_EXPR.

include/ChangeLog:

	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_CONSTRAINTS.

libiberty/ChangeLog:

	* cp-demangle.c (d_make_comp): Handle
	DEMANGLE_COMPONENT_CONSTRAINTS.
	(d_count_templates_scopes): Likewise.
	(d_print_comp_inner): Likewise.
	(d_maybe_constraints): New.
	(d_encoding, d_template_args_1): Call it.
	(d_parmlist): Handle 'Q'.
	* testsuite/demangle-expected: Add some constraint tests.

libstdc++-v3/ChangeLog:

	* include/std/bit: Avoid builtins in requires-clauses.
	* include/std/variant: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle10.C: Disable compat aliases.
	* g++.dg/abi/mangle52.C: Specify ABI 18.
	* g++.dg/cpp2a/class-deduction-alias3.C
	* g++.dg/cpp2a/class-deduction-alias8.C:
	Avoid builtins in requires-clauses.
	* g++.dg/abi/mangle-concepts1.C: New test.
	* g++.dg/abi/mangle-ttp1.C: New test.
Blackhex pushed a commit to Windows-on-ARM-Experiments/gcc-woarm64 that referenced this issue Dec 18, 2023
Per itanium-cxx-abi/cxx-abi#24 and
itanium-cxx-abi/cxx-abi#166

We need to mangle constraints to be able to distinguish between function
templates that only differ in constraints.  From the latter link, we want to
use the template parameter mangling previously specified for lambdas to also
make explicit the form of a template parameter where the argument is not a
"natural" fit for it, such as when the parameter is constrained or deduced.

I'm concerned about how the latter link changes the mangling for some C++98
and C++11 patterns, so I've limited template_parm_natural_p to avoid two
cases found by running the testsuite with -Wabi forced on:

template <class T, T V> T f() { return V; }
int main() { return f<int,42>(); }

template <int i> int max() { return i; }
template <int i, int j, int... rest> int max()
{
  int sub = max<j, rest...>();
  return i > sub ? i : sub;
}
int main() {  return max<1,2,3>(); }

A third C++11 pattern is changed by this patch:

template <template <typename...> class TT, typename... Ts> TT<Ts...> f();
template <typename> struct A { };
int main() { f<A,int>(); }

I aim to resolve these with the ABI committee before GCC 14.1.

We also need to resolve itanium-cxx-abi/cxx-abi#38
(mangling references to dependent template-ids where the name is fully
resolved) as references to concepts in std:: will consistently run into this
area.  This is why mangle-concepts1.C only refers to concepts in the global
namespace so far.

The library changes are to avoid trying to mangle builtins, which fails.

Demangler support and test coverage is not complete yet.

gcc/cp/ChangeLog:

	* cp-tree.h (TEMPLATE_ARGS_TYPE_CONSTRAINT_P): New.
	(get_concept_check_template): Declare.
	* constraint.cc (combine_constraint_expressions)
	(finish_shorthand_constraint): Use UNKNOWN_LOCATION.
	* pt.cc (convert_generic_types_to_packs): Likewise.
	* mangle.cc (write_constraint_expression)
	(write_tparms_constraints, write_type_constraint)
	(template_parm_natural_p, write_requirement)
	(write_requires_expr): New.
	(write_encoding): Mangle trailing requires-clause.
	(write_name): Pass parms to write_template_args.
	(write_template_param_decl): Factor out from...
	(write_closure_template_head): ...here.
	(write_template_args): Mangle non-natural parms
	and requires-clause.
	(write_expression): Handle REQUIRES_EXPR.

include/ChangeLog:

	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_CONSTRAINTS.

libiberty/ChangeLog:

	* cp-demangle.c (d_make_comp): Handle
	DEMANGLE_COMPONENT_CONSTRAINTS.
	(d_count_templates_scopes): Likewise.
	(d_print_comp_inner): Likewise.
	(d_maybe_constraints): New.
	(d_encoding, d_template_args_1): Call it.
	(d_parmlist): Handle 'Q'.
	* testsuite/demangle-expected: Add some constraint tests.

libstdc++-v3/ChangeLog:

	* include/std/bit: Avoid builtins in requires-clauses.
	* include/std/variant: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle10.C: Disable compat aliases.
	* g++.dg/abi/mangle52.C: Specify ABI 18.
	* g++.dg/cpp2a/class-deduction-alias3.C
	* g++.dg/cpp2a/class-deduction-alias8.C:
	Avoid builtins in requires-clauses.
	* g++.dg/abi/mangle-concepts1.C: New test.
	* g++.dg/abi/mangle-ttp1.C: New test.
saagarjha pushed a commit to ahjragaas/binutils-gdb that referenced this issue Jan 9, 2024
…er gcc versions.

This brings in the following commits:

commit c73cc6fe6207b2863afa31a3be8ad87b70d3df0a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Dec 5 23:32:19 2023 +0100

    libiberty: Fix build with GCC < 7

    Tobias reported on IRC that the linker fails to build with GCC 4.8.5.
    In configure I've tried to use everything actually used in the sha1.c
    x86 hw implementation, but unfortunately I forgot about implicit function
    declarations.  GCC before 7 did have <cpuid.h> header and bit_SHA define
    and __get_cpuid function defined inline, but it didn't define
    __get_cpuid_count, which compiled fine (and the configure test is
    intentionally compile time only) due to implicit function declaration,
    but then failed to link when linking the linker, because
    __get_cpuid_count wasn't defined anywhere.

    The following patch fixes that by using what autoconf uses in AC_CHECK_DECL
    to make sure the functions are declared.

commit 691858d279335eeeeed3afafdf872b1c5f8f4201
Author: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Date:   Tue Dec 5 11:04:06 2023 +0100

    libiberty: Fix pex_unix_wait return type

    The recent warning patches broke Solaris bootstrap:

    /vol/gcc/src/hg/master/local/libiberty/pex-unix.c:326:3: error: initialization of 'pid_t (*)(struct pex_obj *, pid_t,  int *, struct pex_time *, int,  const char **, int *)' {aka 'long int (*)(struct pex_obj *, long int,  int *, struct pex_time *, int,  const char **, int *)'} from incompatible pointer type 'int (*)(struct pex_obj *, pid_t,  int *, struct pex_time *, int,  const char **, int *)' {aka 'int (*)(struct pex_obj *, long int,  int *, struct pex_time *, int,  const char **, int *)'} [-Wincompatible-pointer-types]
      326 |   pex_unix_wait,
          |   ^~~~~~~~~~~~~
    /vol/gcc/src/hg/master/local/libiberty/pex-unix.c:326:3: note: (near initialization for 'funcs.wait')

    While pex_funcs.wait expects a function returning pid_t, pex_unix_wait
    currently returns int.  However, on Solaris pid_t is long for 32-bit,
    but int for 64-bit.

    This patches fixes this by having pex_unix_wait return pid_t as
    expected, and like every other variant already does.

    Bootstrapped without regressions on i386-pc-solaris2.11,
    sparc-sun-solaris2.11, x86_64-pc-linux-gnu, and
    x86_64-apple-darwin23.1.0.

commit c3f281a0c1ca50e4df5049923aa2f5d1c3c39ff6
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Sep 25 10:15:02 2023 +0100

    c++: mangle function template constraints

    Per itanium-cxx-abi/cxx-abi#24 and
    itanium-cxx-abi/cxx-abi#166

    We need to mangle constraints to be able to distinguish between function
    templates that only differ in constraints.  From the latter link, we want to
    use the template parameter mangling previously specified for lambdas to also
    make explicit the form of a template parameter where the argument is not a
    "natural" fit for it, such as when the parameter is constrained or deduced.

    I'm concerned about how the latter link changes the mangling for some C++98
    and C++11 patterns, so I've limited template_parm_natural_p to avoid two
    cases found by running the testsuite with -Wabi forced on:

    template <class T, T V> T f() { return V; }
    int main() { return f<int,42>(); }

    template <int i> int max() { return i; }
    template <int i, int j, int... rest> int max()
    {
      int sub = max<j, rest...>();
      return i > sub ? i : sub;
    }
    int main() {  return max<1,2,3>(); }

    A third C++11 pattern is changed by this patch:

    template <template <typename...> class TT, typename... Ts> TT<Ts...> f();
    template <typename> struct A { };
    int main() { f<A,int>(); }

    I aim to resolve these with the ABI committee before GCC 14.1.

    We also need to resolve itanium-cxx-abi/cxx-abi#38
    (mangling references to dependent template-ids where the name is fully
    resolved) as references to concepts in std:: will consistently run into this
    area.  This is why mangle-concepts1.C only refers to concepts in the global
    namespace so far.

    The library changes are to avoid trying to mangle builtins, which fails.

    Demangler support and test coverage is not complete yet.

commit f2c52c0dfde581461959b0e2b423ad106aadf179
Author: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Date:   Thu Nov 30 10:06:23 2023 +0100

    libiberty: Disable hwcaps for sha1.o

    This patch

    commit bf4f40cc3195eb7b900bf5535cdba1ee51fdbb8e
    Author: Jakub Jelinek <jakub@redhat.com>
    Date:   Tue Nov 28 13:14:05 2023 +0100

        libiberty: Use x86 HW optimized sha1

    broke Solaris/x86 bootstrap with the native as:

    libtool: compile:  /var/gcc/regression/master/11.4-gcc/build/./gcc/gccgo -B/var/gcc/regression/master/11.4-gcc/build/./gcc/ -B/vol/gcc/i386-pc-solaris2.11/bin/ -B/vol/gcc/i386-pc-solaris2.11/lib/ -isystem /vol/gcc/i386-pc-solaris2.11/include -isystem /vol/gcc/i386-pc-solaris2.11/sys-include -fchecking=1 -minline-all-stringops -O2 -g -I . -c -fgo-pkgpath=internal/goarch /vol/gcc/src/hg/master/local/libgo/go/internal/goarch/goarch.go zgoarch.go
    ld.so.1: go1: fatal: /var/gcc/regression/master/11.4-gcc/build/gcc/go1: hardware capability (CA_SUNW_HW_2) unsupported: 0x4000000  [ SHA1 ]
    gccgo: fatal error: Killed signal terminated program go1

    As is already done in a couple of other similar cases, this patches
    disables hwcaps support for libiberty.

    Initially, this didn't work because config/hwcaps.m4 uses target_os, but
    didn't ensure it is defined.

    Tested on i386-pc-solaris2.11 with as and gas.

commit bf4f40cc3195eb7b900bf5535cdba1ee51fdbb8e
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Nov 28 13:14:05 2023 +0100

    libiberty: Use x86 HW optimized sha1

    Nick has approved this patch (+ small ld change to use it for --build-id=),
    so I'm commiting it to GCC as master as well.

    If anyone from ARM would be willing to implement it similarly with
    vsha1{cq,mq,pq,h,su0q,su1q}_u32 intrinsics, it could be a useful linker
    speedup on those hosts as well, the intent in sha1.c was that
    sha1_hw_process_bytes, sha1_hw_process_block functions
    would be defined whenever
    defined (HAVE_X86_SHA1_HW_SUPPORT) || defined (HAVE_WHATEVERELSE_SHA1_HW_SUPPORT)
    but the body of sha1_hw_process_block and sha1_choose_process_bytes
    would then have #elif defined (HAVE_WHATEVERELSE_SHA1_HW_SUPPORT) for
    the other arch support, similarly for any target attributes on
    sha1_hw_process_block if needed.

commit 01bc30b222a9d2ff0269325d9e367f8f1fcef942
Author: Mark Wielaard <mjw@redhat.com>
Date:   Wed Nov 15 20:27:08 2023 +0100

    Regenerate libiberty/aclocal.m4 with aclocal 1.15.1

    There is a new buildbot check that all autotool files are generated
    with the correct versions (automake 1.15.1 and autoconf 2.69).
    https://builder.sourceware.org/buildbot/#/builders/gcc-autoregen

    Correct one file that was generated with the wrong version.

commit 879cf9ff45d94065d89e24b71c6b27c7076ac518
Author: Brendan Shanks <bshanks@codeweavers.com>
Date:   Thu Nov 9 21:01:07 2023 -0700

    [PATCH v3] libiberty: Use posix_spawn in pex-unix when available.

    Hi,

    This patch implements pex_unix_exec_child using posix_spawn when
    available.

    This should especially benefit recent macOS (where vfork just calls
    fork), but should have equivalent or faster performance on all
    platforms.
    In addition, the implementation is substantially simpler than the
    vfork+exec code path.

    Tested on x86_64-linux.

    v2: Fix error handling (previously the function would be run twice in
    case of error), and don't use a macro that changes control flow.

    v3: Match file style for error-handling blocks, don't close
    in/out/errdes on error, and check close() for errors.

commit 810bcc00156cefce7ad40fc9d8de6e43c3a04450
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Aug 17 11:36:23 2023 -0400

    c++: constrained hidden friends [PR109751]

    r13-4035 avoided a problem with overloading of constrained hidden friends by
    checking satisfaction, but checking satisfaction early is inconsistent with
    the usual late checking and can lead to hard errors, so let's not do that
    after all.

    We were wrongly treating the different instantiations of the same friend
    template as the same function because maybe_substitute_reqs_for was failing
    to actually substitute in the case of a non-template friend.  But we don't
    actually need to do the substitution anyway, because [temp.friend] says that
    such a friend can't be the same as any other declaration.

    After fixing that, instead of a redefinition error we got an ambiguous
    overload error, fixed by allowing constrained hidden friends to coexist
    until overload resolution, at which point they probably won't be in the same
    ADL overload set anyway.

    And we avoid mangling collisions by following the proposed mangling for
    these friends as a member function with an extra 'F' before the name.  I
    demangle this by just adding [friend] to the name of the function because
    it's not feasible to reconstruct the actual scope of the function since the
    mangling ABI doesn't distinguish between class and namespace scopes.

            PR c++/109751
Liaoshihua pushed a commit to Liaoshihua/ruyi-gcc that referenced this issue Mar 11, 2024
Per itanium-cxx-abi/cxx-abi#24 and
itanium-cxx-abi/cxx-abi#166

We need to mangle constraints to be able to distinguish between function
templates that only differ in constraints.  From the latter link, we want to
use the template parameter mangling previously specified for lambdas to also
make explicit the form of a template parameter where the argument is not a
"natural" fit for it, such as when the parameter is constrained or deduced.

I'm concerned about how the latter link changes the mangling for some C++98
and C++11 patterns, so I've limited template_parm_natural_p to avoid two
cases found by running the testsuite with -Wabi forced on:

template <class T, T V> T f() { return V; }
int main() { return f<int,42>(); }

template <int i> int max() { return i; }
template <int i, int j, int... rest> int max()
{
  int sub = max<j, rest...>();
  return i > sub ? i : sub;
}
int main() {  return max<1,2,3>(); }

A third C++11 pattern is changed by this patch:

template <template <typename...> class TT, typename... Ts> TT<Ts...> f();
template <typename> struct A { };
int main() { f<A,int>(); }

I aim to resolve these with the ABI committee before GCC 14.1.

We also need to resolve itanium-cxx-abi/cxx-abi#38
(mangling references to dependent template-ids where the name is fully
resolved) as references to concepts in std:: will consistently run into this
area.  This is why mangle-concepts1.C only refers to concepts in the global
namespace so far.

The library changes are to avoid trying to mangle builtins, which fails.

Demangler support and test coverage is not complete yet.

gcc/cp/ChangeLog:

	* cp-tree.h (TEMPLATE_ARGS_TYPE_CONSTRAINT_P): New.
	(get_concept_check_template): Declare.
	* constraint.cc (combine_constraint_expressions)
	(finish_shorthand_constraint): Use UNKNOWN_LOCATION.
	* pt.cc (convert_generic_types_to_packs): Likewise.
	* mangle.cc (write_constraint_expression)
	(write_tparms_constraints, write_type_constraint)
	(template_parm_natural_p, write_requirement)
	(write_requires_expr): New.
	(write_encoding): Mangle trailing requires-clause.
	(write_name): Pass parms to write_template_args.
	(write_template_param_decl): Factor out from...
	(write_closure_template_head): ...here.
	(write_template_args): Mangle non-natural parms
	and requires-clause.
	(write_expression): Handle REQUIRES_EXPR.

include/ChangeLog:

	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_CONSTRAINTS.

libiberty/ChangeLog:

	* cp-demangle.c (d_make_comp): Handle
	DEMANGLE_COMPONENT_CONSTRAINTS.
	(d_count_templates_scopes): Likewise.
	(d_print_comp_inner): Likewise.
	(d_maybe_constraints): New.
	(d_encoding, d_template_args_1): Call it.
	(d_parmlist): Handle 'Q'.
	* testsuite/demangle-expected: Add some constraint tests.

libstdc++-v3/ChangeLog:

	* include/std/bit: Avoid builtins in requires-clauses.
	* include/std/variant: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle10.C: Disable compat aliases.
	* g++.dg/abi/mangle52.C: Specify ABI 18.
	* g++.dg/cpp2a/class-deduction-alias3.C
	* g++.dg/cpp2a/class-deduction-alias8.C:
	Avoid builtins in requires-clauses.
	* g++.dg/abi/mangle-concepts1.C: New test.
	* g++.dg/abi/mangle-ttp1.C: New test.
Liaoshihua pushed a commit to Liaoshihua/ruyi-gcc that referenced this issue Mar 11, 2024
Per itanium-cxx-abi/cxx-abi#24 and
itanium-cxx-abi/cxx-abi#166

We need to mangle constraints to be able to distinguish between function
templates that only differ in constraints.  From the latter link, we want to
use the template parameter mangling previously specified for lambdas to also
make explicit the form of a template parameter where the argument is not a
"natural" fit for it, such as when the parameter is constrained or deduced.

I'm concerned about how the latter link changes the mangling for some C++98
and C++11 patterns, so I've limited template_parm_natural_p to avoid two
cases found by running the testsuite with -Wabi forced on:

template <class T, T V> T f() { return V; }
int main() { return f<int,42>(); }

template <int i> int max() { return i; }
template <int i, int j, int... rest> int max()
{
  int sub = max<j, rest...>();
  return i > sub ? i : sub;
}
int main() {  return max<1,2,3>(); }

A third C++11 pattern is changed by this patch:

template <template <typename...> class TT, typename... Ts> TT<Ts...> f();
template <typename> struct A { };
int main() { f<A,int>(); }

I aim to resolve these with the ABI committee before GCC 14.1.

We also need to resolve itanium-cxx-abi/cxx-abi#38
(mangling references to dependent template-ids where the name is fully
resolved) as references to concepts in std:: will consistently run into this
area.  This is why mangle-concepts1.C only refers to concepts in the global
namespace so far.

The library changes are to avoid trying to mangle builtins, which fails.

Demangler support and test coverage is not complete yet.

gcc/cp/ChangeLog:

	* cp-tree.h (TEMPLATE_ARGS_TYPE_CONSTRAINT_P): New.
	(get_concept_check_template): Declare.
	* constraint.cc (combine_constraint_expressions)
	(finish_shorthand_constraint): Use UNKNOWN_LOCATION.
	* pt.cc (convert_generic_types_to_packs): Likewise.
	* mangle.cc (write_constraint_expression)
	(write_tparms_constraints, write_type_constraint)
	(template_parm_natural_p, write_requirement)
	(write_requires_expr): New.
	(write_encoding): Mangle trailing requires-clause.
	(write_name): Pass parms to write_template_args.
	(write_template_param_decl): Factor out from...
	(write_closure_template_head): ...here.
	(write_template_args): Mangle non-natural parms
	and requires-clause.
	(write_expression): Handle REQUIRES_EXPR.

include/ChangeLog:

	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_CONSTRAINTS.

libiberty/ChangeLog:

	* cp-demangle.c (d_make_comp): Handle
	DEMANGLE_COMPONENT_CONSTRAINTS.
	(d_count_templates_scopes): Likewise.
	(d_print_comp_inner): Likewise.
	(d_maybe_constraints): New.
	(d_encoding, d_template_args_1): Call it.
	(d_parmlist): Handle 'Q'.
	* testsuite/demangle-expected: Add some constraint tests.

libstdc++-v3/ChangeLog:

	* include/std/bit: Avoid builtins in requires-clauses.
	* include/std/variant: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle10.C: Disable compat aliases.
	* g++.dg/abi/mangle52.C: Specify ABI 18.
	* g++.dg/cpp2a/class-deduction-alias3.C
	* g++.dg/cpp2a/class-deduction-alias8.C:
	Avoid builtins in requires-clauses.
	* g++.dg/abi/mangle-concepts1.C: New test.
	* g++.dg/abi/mangle-ttp1.C: New test.
Liaoshihua pushed a commit to Liaoshihua/gcc that referenced this issue Mar 19, 2024
Per itanium-cxx-abi/cxx-abi#24 and
itanium-cxx-abi/cxx-abi#166

We need to mangle constraints to be able to distinguish between function
templates that only differ in constraints.  From the latter link, we want to
use the template parameter mangling previously specified for lambdas to also
make explicit the form of a template parameter where the argument is not a
"natural" fit for it, such as when the parameter is constrained or deduced.

I'm concerned about how the latter link changes the mangling for some C++98
and C++11 patterns, so I've limited template_parm_natural_p to avoid two
cases found by running the testsuite with -Wabi forced on:

template <class T, T V> T f() { return V; }
int main() { return f<int,42>(); }

template <int i> int max() { return i; }
template <int i, int j, int... rest> int max()
{
  int sub = max<j, rest...>();
  return i > sub ? i : sub;
}
int main() {  return max<1,2,3>(); }

A third C++11 pattern is changed by this patch:

template <template <typename...> class TT, typename... Ts> TT<Ts...> f();
template <typename> struct A { };
int main() { f<A,int>(); }

I aim to resolve these with the ABI committee before GCC 14.1.

We also need to resolve itanium-cxx-abi/cxx-abi#38
(mangling references to dependent template-ids where the name is fully
resolved) as references to concepts in std:: will consistently run into this
area.  This is why mangle-concepts1.C only refers to concepts in the global
namespace so far.

The library changes are to avoid trying to mangle builtins, which fails.

Demangler support and test coverage is not complete yet.

gcc/cp/ChangeLog:

	* cp-tree.h (TEMPLATE_ARGS_TYPE_CONSTRAINT_P): New.
	(get_concept_check_template): Declare.
	* constraint.cc (combine_constraint_expressions)
	(finish_shorthand_constraint): Use UNKNOWN_LOCATION.
	* pt.cc (convert_generic_types_to_packs): Likewise.
	* mangle.cc (write_constraint_expression)
	(write_tparms_constraints, write_type_constraint)
	(template_parm_natural_p, write_requirement)
	(write_requires_expr): New.
	(write_encoding): Mangle trailing requires-clause.
	(write_name): Pass parms to write_template_args.
	(write_template_param_decl): Factor out from...
	(write_closure_template_head): ...here.
	(write_template_args): Mangle non-natural parms
	and requires-clause.
	(write_expression): Handle REQUIRES_EXPR.

include/ChangeLog:

	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_CONSTRAINTS.

libiberty/ChangeLog:

	* cp-demangle.c (d_make_comp): Handle
	DEMANGLE_COMPONENT_CONSTRAINTS.
	(d_count_templates_scopes): Likewise.
	(d_print_comp_inner): Likewise.
	(d_maybe_constraints): New.
	(d_encoding, d_template_args_1): Call it.
	(d_parmlist): Handle 'Q'.
	* testsuite/demangle-expected: Add some constraint tests.

libstdc++-v3/ChangeLog:

	* include/std/bit: Avoid builtins in requires-clauses.
	* include/std/variant: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle10.C: Disable compat aliases.
	* g++.dg/abi/mangle52.C: Specify ABI 18.
	* g++.dg/cpp2a/class-deduction-alias3.C
	* g++.dg/cpp2a/class-deduction-alias8.C:
	Avoid builtins in requires-clauses.
	* g++.dg/abi/mangle-concepts1.C: New test.
	* g++.dg/abi/mangle-ttp1.C: New test.
VitaNuo added a commit to VitaNuo/llvm-project that referenced this issue Sep 27, 2024
…aint that depends on a template parameter from an enclosing template as members of the enclosing class.

Such function templates should be considered member-like constrained friends per [temp.friend]p9 and itanium-cxx-abi/cxx-abi#24 (comment)).
VitaNuo added a commit to llvm/llvm-project that referenced this issue Sep 30, 2024
#110247)

…aint that depends on a template parameter from an enclosing template as
members of the enclosing class.

Such function templates should be considered member-like constrained
friends per [temp.friend]p9 and
itanium-cxx-abi/cxx-abi#24 (comment)).
puja2196 pushed a commit to puja2196/LLVM-tutorial that referenced this issue Sep 30, 2024
…… (#110247)

…aint that depends on a template parameter from an enclosing template as
members of the enclosing class.

Such function templates should be considered member-like constrained
friends per [temp.friend]p9 and
itanium-cxx-abi/cxx-abi#24 (comment)).
puja2196 pushed a commit to puja2196/LLVM-tutorial that referenced this issue Oct 2, 2024
…… (#110247)

…aint that depends on a template parameter from an enclosing template as
members of the enclosing class.

Such function templates should be considered member-like constrained
friends per [temp.friend]p9 and
itanium-cxx-abi/cxx-abi#24 (comment)).
xgupta pushed a commit to xgupta/llvm-project that referenced this issue Oct 4, 2024
llvm#110247)

…aint that depends on a template parameter from an enclosing template as
members of the enclosing class.

Such function templates should be considered member-like constrained
friends per [temp.friend]p9 and
itanium-cxx-abi/cxx-abi#24 (comment)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending committee feedback The issue is blocked waiting for a response from the committee.
Projects
None yet
Development

No branches or pull requests

10 participants