https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81270
Bug ID: 81270
Summary: [concepts] ill-formed code with a constrained variable
declaration with multiple declarators with different
deduced types not rejected
Product: gcc
Version: c++-concepts
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tom at honermann dot net
CC: andrew.n.sutton at gmail dot com, asutton at gcc dot gnu.org
Target Milestone: ---
The Concepts TS (N4674) updates § 10.1.7.4 [dcl.spec.auto] paragraph 9
(paragraph 7 in the current WP) to state:
> If the init-declarator-list contains more than one init-declarator, they
> shall all form declarations of variables. The type of each declared
> variable is determined by placeholder type deduction (10.1.7.4.1), and if
> the type that replaces the declared variable type or return type is not
> the same in each deduction, the program is ill-formed.
gcc 7.1.0 fails to diagnose the following code that is ill-formed due to a
different type being deduced for each of the v1 and v2 declarators:
$ cat t.cpp
template<typename> concept bool C = true;
C v1 = 1, v2 = nullptr; // Ill-formed.
// Following code to demonstrate that the types of v1 and v2 are deduced
// to different types.
template<typename, typename> struct is_same {
static constexpr bool value = false;
};
template<typename T> struct is_same<T,T> {
static constexpr bool value = true;
};
static_assert(is_same<decltype(v1),int>::value);
static_assert(is_same<decltype(v2),decltype(nullptr)>::value);
$ g++ --version
g++ (GCC) 7.1.0
...
$ g++ -c -fconcepts t.cpp
<no error>
The expectation is that gcc reject the above code as it does if the declared
variable type C is replaced with auto:
$ cat t2.cpp
auto v1 = 1, v2 = nullptr;
$ g++ -c -fconcepts t2.cpp
t2.cpp:1:1: error: inconsistent deduction for ‘auto’: ‘int’ and then
‘std::nullptr_t’
auto v1 = 1, v2 = nullptr;
^~~~