Skip to content

CWG3110 [expr.const] Should literal-ness of the element type invalidate constexpr allocation? #792

Description

@frederick-vs-ja

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [expr.const]

Link to reflector thread (if any):

Issue description:

Currently, [expr.const] p14 says:

For the purposes of determining whether an expression E is a core constant expression, the evaluation of the body of a member function of std::allocator<T> as defined in [allocator.members], where T is a literal type, is ignored.

It seems that when T is not a literal type, there is (or can be?) constant evaluation failure, as the function bodies that generally call non-constexpr ::operator new/::operator delete are not ignored.

However, implementations consistently accept the following example (Godbolt link) despite that std::locale is not a literal type.

#include <locale>
#include <memory>

static_assert([]{
  auto a = std::allocator<std::locale>{};
  a.deallocate(a.allocate(42), 42);
  return true;
}());

It's possibly more reasonable not to require literal-ness here as no non-constexpr function call is made.

Suggested resolution:

Modify [expr.const] as indicated:

  1. For the purposes of determining whether an expression E is a core constant expression, the evaluation of the body of a member function of std::allocator<T> as defined in [allocator.members], where T is a literal type, is ignored.
    [...]

Activity

  1. jensmaurer commented on Nov 2, 2025

    @jensmaurer
    Member
  2. changed the title [-][expr.const] Should literal-ness of the element type invalidate constexpr allocation?[/-] [+]CWG3110 [expr.const] Should literal-ness of the element type invalidate constexpr allocation?[/+] on Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions