[llvm-bugs] [Bug 48286] New: Not treating unions with at least one literal member as literal

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 24 10:13:14 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=48286

            Bug ID: 48286
           Summary: Not treating unions with at least one literal member
                    as literal
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ant.bikineev at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Clang fails to compile the following code:

std::optional<NonLiteral> unpopulated{};

The reduced example is:

template <typename T>
struct A {
  union {
    char c = 0;
    T t;
  };
};

constexpr A<NonLiteral> unpopulated{};

The error clang emits is:
error: constexpr variable cannot have non-literal type 'const A<NonLiteral>'
constexpr A<NonLiteral> unpopulated{};
                        ^
note: 'A<NonLiteral>' is not literal because it has data member '' of
non-literal type 'union (anonymous union at ...)'

A relevant section from the Standard (unless I'm missing another one):
[6.8.1.10]
A type is a literal type if it is:
 - ...
 - if it is a union, at least one of its non-static data members is of
non-volatile literal type, and ...

gcc succeeds to compile this example.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201124/e1feb808/attachment.html>


More information about the llvm-bugs mailing list