[llvm-bugs] [Bug 47047] New: Unexpected constexpr assignment error relating to object lifetime and std::allocator

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 7 17:17:54 PDT 2020


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

            Bug ID: 47047
           Summary: Unexpected constexpr assignment error relating to
                    object lifetime and std::allocator
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pkeir at outlook.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Created attachment 23830
  --> https://bugs.llvm.org/attachment.cgi?id=23830&action=edit
A C++ file containing the code described.

The C++20 code below (also attached) fails to compile, with clang reporting
that the "static_assert expression is not an integral constant expression". In
relation to `*p = 42;` clang also notes: "assignment to object outside its
lifetime is not allowed in a constant expression". I believe such use of
`std::allocator` is now permitted within a `constexpr` context. As well as
trunk, the error can be observed using stock clang on Ubuntu 20.04, but at
least version 10 of libstdc++ should be used for its `constexpr`
`std::allocator`. The code compiles and runs with GCC.

#include <memory>

constexpr bool ptr_test()
{
  std::allocator<int> alloc;
  int *p = alloc.allocate(1);
  *p = 42;
  int i = *p;
  alloc.deallocate(p,1);

  return i==42;
}

int main(int argc, char *argv[])
{
  static_assert(ptr_test());

  return ptr_test() ? 0 : -1;
}

-- 
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/20200808/5eaf7855/attachment.html>


More information about the llvm-bugs mailing list