Bug 102157 - floating-integral conversions is not permitted in the user-defined conversion sequence in converted constant expression
Summary: floating-integral conversions is not permitted in the user-defined conversion...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2021-09-01 07:35 UTC by jim x
Modified: 2021-09-02 03:11 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-09-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jim x 2021-09-01 07:35:06 UTC
struct A{
    constexpr A(double const& rf){}
};
template<class T, T B>
struct C{};
int main() {
    C<A,0> b;
}

This code is accepted by GCC while rejected by Clang.  

[temp.arg.nontype] p2 
> A template-argument for a non-type template-parameter shall be a converted constant expression ([expr.const]) of the type of the template-parameter.  

From a prvalue of type `int` to type `A`, the user-defined conversion sequence will involve floating-integral conversions that are not permitted in [expr.const] p10. GCC should reject this example.
Comment 1 Drea Pinski 2021-09-01 22:07:28 UTC
There are two issues here really (both accepts invalid).
First is binding to a temp is invalid:
struct A{
    constexpr A(double const &rf){}
};
template<class T, T B>
struct C{};
int main() {
    C<A,0.> b;
}
----- CUT ----
Second is the conversion is also invalid:
struct A{
    constexpr A(double rf){}
};
template<class T, T B>
struct C{};
int main() {
    C<A,0> b;
}
Comment 2 jim x 2021-09-02 03:11:52 UTC
bind the temporary is permitted here to me. Since the template parameter is not a reference type, there is no restriction on whether a temporary object is generated in the implicit conversion.