public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit
@ 2020-05-11 17:50 ojman101 at protonmail dot com
2020-05-11 17:57 ` [Bug c++/95066] " ojman101 at protonmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: ojman101 at protonmail dot com @ 2020-05-11 17:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
Bug ID: 95066
Summary: [C++ 20] Incorrect valid compilation with a
conditional explicit
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ojman101 at protonmail dot com
Target Milestone: ---
The code below is invalid C++, the line "Foo<int> b = a;" should fail to
compile as implicitly casting is made illegal by the conditional explicit using
the "IsSafelyCastable" predicate.
----------------------------------------------------------------
#include <type_traits>
template <typename, typename>
class IsSafelyCastable : public std::false_type {};
template <>
class IsSafelyCastable<int, float> : public std::true_type {};
template <typename T>
struct Foo {
template <typename U>
explicit(!IsSafelyCastable<T, U>::value) operator Foo<U>();
};
template <typename T>
template <typename U>
Foo<T>::operator Foo<U>() {
return {};
}
int main() {
Foo<float> a;
Foo<int> b = a;
}
----------------------------------------------------------------
Clang 10 correctly evaluates the explicit condition to be true and blocks the
implicit cast. However, GCC 9.3.0 successfully compiles without any errors. I
believe this to be a GCC bug as subtle changes can make GCC produce the correct
error. For example, moving the definition of the function to be inline with the
declaration.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/95066] [C++ 20] Incorrect valid compilation with a conditional explicit
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
@ 2020-05-11 17:57 ` ojman101 at protonmail dot com
2020-05-11 18:26 ` [Bug c++/95066] [C++ 20] Incorrect successful " mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ojman101 at protonmail dot com @ 2020-05-11 17:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
--- Comment #1 from Owen Smith <ojman101 at protonmail dot com> ---
----------------------------------------------------------------
#include <type_traits>
template <typename, typename>
class IsSafelyCastable : public std::false_type {};
template <>
class IsSafelyCastable<int, float> : public std::true_type {};
template <typename T>
struct Foo {
template <typename U>
explicit(!IsSafelyCastable<T, U>::value) operator Foo<U>() { return {}; }
};
int main() {
Foo<float> a;
Foo<int> b = a;
}
----------------------------------------------------------------
Inlining the definition yields the correct error with GCC 9.3.0:
----------------------------------------------------------------
main.cpp: In function 'int main()':
main.cpp:17:18: error: conversion from 'Foo<float>' to non-scalar type
'Foo<int>' requested
17 | Foo<int> b = a;
|
----------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/95066] [C++ 20] Incorrect successful compilation with a conditional explicit
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
2020-05-11 17:57 ` [Bug c++/95066] " ojman101 at protonmail dot com
@ 2020-05-11 18:26 ` mpolacek at gcc dot gnu.org
2020-05-11 22:00 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-11 18:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2020-05-11
Keywords| |accepts-invalid
Ever confirmed|0 |1
CC| |mpolacek at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks for the report. In the first case we don't seem to ever substitute the
explicit-specifier. I think we forget to lookup the explicit-specifier when
instantiating the out-of-line definition of operator Foo.
Since I've implemented explicit(bool), mine.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/95066] [C++ 20] Incorrect successful compilation with a conditional explicit
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
2020-05-11 17:57 ` [Bug c++/95066] " ojman101 at protonmail dot com
2020-05-11 18:26 ` [Bug c++/95066] [C++ 20] Incorrect successful " mpolacek at gcc dot gnu.org
@ 2020-05-11 22:00 ` mpolacek at gcc dot gnu.org
2020-05-11 23:07 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-11 22:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Reduced:
template <typename T>
struct Foo {
template <typename U>
explicit(static_cast<U>(true)) operator Foo<U>();
};
template <typename T>
template <typename U>
Foo<T>::operator Foo<U>() {
return {};
}
int
main ()
{
Foo<float> a;
Foo<int> b = a;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/95066] [C++ 20] Incorrect successful compilation with a conditional explicit
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
` (2 preceding siblings ...)
2020-05-11 22:00 ` mpolacek at gcc dot gnu.org
@ 2020-05-11 23:07 ` mpolacek at gcc dot gnu.org
2020-05-13 20:26 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-11 23:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch posted: https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545565.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/95066] [C++ 20] Incorrect successful compilation with a conditional explicit
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
` (3 preceding siblings ...)
2020-05-11 23:07 ` mpolacek at gcc dot gnu.org
@ 2020-05-13 20:26 ` cvs-commit at gcc dot gnu.org
2020-06-11 20:33 ` cvs-commit at gcc dot gnu.org
2020-06-11 20:33 ` mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-13 20:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:661232da72d29f8f2385d5f588727beb74360144
commit r11-371-g661232da72d29f8f2385d5f588727beb74360144
Author: Marek Polacek <polacek@redhat.com>
Date: Mon May 11 18:28:19 2020 -0400
c++: explicit(bool) malfunction with dependent expression [PR95066]
I forgot to set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P when merging two
function declarations and as a sad consequence, we never tsubsted
the dependent explicit-specifier in tsubst_function_decl, leading to
disregarding the explicit-specifier altogether, and wrongly accepting
this test.
PR c++/95066
* decl.c (duplicate_decls): Set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P.
* g++.dg/cpp2a/explicit16.C: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/95066] [C++ 20] Incorrect successful compilation with a conditional explicit
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
` (4 preceding siblings ...)
2020-05-13 20:26 ` cvs-commit at gcc dot gnu.org
@ 2020-06-11 20:33 ` cvs-commit at gcc dot gnu.org
2020-06-11 20:33 ` mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-11 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:ae275b986b8cc747a5b4f389cb05a71fdee1f886
commit r10-8280-gae275b986b8cc747a5b4f389cb05a71fdee1f886
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Jun 11 16:33:13 2020 -0400
c++: explicit(bool) malfunction with dependent expression [PR95066]
I forgot to set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P when merging two
function declarations and as a sad consequence, we never tsubsted
the dependent explicit-specifier in tsubst_function_decl, leading to
disregarding the explicit-specifier altogether, and wrongly accepting
this test.
PR c++/95066
* decl.c (duplicate_decls): Set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P.
* g++.dg/cpp2a/explicit16.C: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/95066] [C++ 20] Incorrect successful compilation with a conditional explicit
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
` (5 preceding siblings ...)
2020-06-11 20:33 ` cvs-commit at gcc dot gnu.org
@ 2020-06-11 20:33 ` mpolacek at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-06-11 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-06-11 20:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 17:50 [Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit ojman101 at protonmail dot com
2020-05-11 17:57 ` [Bug c++/95066] " ojman101 at protonmail dot com
2020-05-11 18:26 ` [Bug c++/95066] [C++ 20] Incorrect successful " mpolacek at gcc dot gnu.org
2020-05-11 22:00 ` mpolacek at gcc dot gnu.org
2020-05-11 23:07 ` mpolacek at gcc dot gnu.org
2020-05-13 20:26 ` cvs-commit at gcc dot gnu.org
2020-06-11 20:33 ` cvs-commit at gcc dot gnu.org
2020-06-11 20:33 ` mpolacek at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).