https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67217
Bug ID: 67217
Summary: [concepts] Constraints are ignored when specializing
union templates
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Casey at Carter dot net
Target Milestone: ---
r226833 incorrectly compiles this program without diagnostics:
template <class T>
requires __is_same_as(T, double)
union A {};
int main() { A<int>{}; }
despite that int does not satisfy the constraints of A. Changing the expression
__is_same_as(T, double) to true, false, 42, or (new T) has no effect - the
program compiles without diagnostics.
Compiling *this* program, however:
template <class>
union B {};
template <class T>
requires false
union B<T> {};
int main() {
B<int>{};
}
incorrectly produces diagnostics:
~/gcc6-r226833/bin/g++ -std=gnu++1z foo.cpp -c
foo.cpp: In function ‘int main()’:
foo.cpp:9:10: error: ambiguous template instantiation for ‘union B<int>’
B<int>{};
^
foo.cpp:6:7: note: candidates are: template<class T> union B<T> [with T = int]
union B<T> {};
^
foo.cpp:6:12: note: template<class T> union B<T> [with T = int]
union B<T> {};
^
foo.cpp:6:13: note: template<class T> union B<T> [with T = int]
union B<T> {};
^
foo.cpp:9:10: error: invalid use of incomplete type ‘union B<int>’
B<int>{};
^
foo.cpp:2:7: note: declaration of ‘union B<int>’
union B {};
^
It would appear that constraints are not being checked on union templates.