https://bugs.llvm.org/show_bug.cgi?id=47345
Bug ID: 47345
Summary: Constexpr constructor not initializing a union member
is not diagnosed
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++14
Assignee: unassignedclangb...@nondot.org
Reporter: malts...@gmail.com
CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk
Consider the following C++14 code:
template <class> struct C {
union {
int i;
};
constexpr C() {}
};
constexpr C<int> c;
This code is ill-formed because the constructor C does not initialize the data
member i, but Clang fails to diagnose the error.
According to C++14 [dcl.constexpr]/4:
"The definition of a constexpr constructor shall satisfy the following
constraints:
- ...
In addition, either its function-body shall be = delete, or it shall satisfy
the following constraints:
- ...
- if the class is a union-like class, but is not a union, for each of its
anonymous union members having variant members, exactly one of them shall be
initialized;"
[dcl.constexpr]/6:
"If the instantiated template specialization of a constexpr function template
or member function of a class template would fail to satisfy the requirements
for a constexpr function or constexpr constructor, that specialization is still
a constexpr function or constexpr constructor, even though a call to such a
function cannot appear in a constant expression."
GCC produces the following diagnostic:
<source>:7:18: error: 'constexpr C< <template-parameter-1-1> >::C() [with
<template-parameter-1-1> = int]' called in a constant expression
7 | constexpr C<int> c;
| ^
<source>:5:15: note: 'constexpr C< <template-parameter-1-1> >::C() [with
<template-parameter-1-1> = int]' is not usable as a 'constexpr' function
because:
5 | constexpr C() {}
| ^
<source>:5:15: error: 'constexpr' constructor for union 'C<int>::<unnamed
union>' must initialize exactly one non-static data member
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs