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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to