Skip to content

<system_error>: error_category's default ctor isn't constexpr.  #1116

@fsb4000

Description

@fsb4000

Describe the bug
error_category's default ctor isn't constexpr.

Command-line test case

C:\Temp>type test.cpp
#include <system_error>
#include <type_traits>
#include <string>
#include <cassert>


class test1
    : public std::error_category
{
public:
    constexpr test1() = default;  // won't compile if error_category() is not constexpr
    virtual const char* name() const noexcept {return nullptr;}
    virtual std::string message(int) const {return std::string();}
};

int main(int, char**)
{
    static_assert(std::is_nothrow_default_constructible<test1>::value,
                                 "error_category() must exist and be noexcept");

  return 0;
}
C:\Temp>cl /EHsc /W4 /WX  /std:c++latest test.cpp
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.27.29109 для x64
(C) Корпорация Майкрософт (Microsoft Corporation).  Все права защищены.

/std:c++latest предоставляется как предварительная версия языковых функций из последнего
рабочего черновика C++. Мы приветствуем сообщения об ошибках и предложения к улучшению.
Однако обратите внимание, что эти функции предоставляются как есть, без поддержки и могут
измениться или быть удалены по мере развития рабочего черновика. Дополнительные сведения:
https://go.microsoft.com/fwlink/?linkid=2045807.

test.cpp
Microsoft (R) Incremental Linker Version 14.27.29109.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
C:\Temp>.\test.exe

Expected behavior
Should not compile now and should compile when error_category constructor will be constexpr

STL version
Microsoft Visual Studio Community 2019 Preview Version 16.7.0 Preview 6.0
Additional context

# STL Bug: error_category's default ctor isn't constexpr. (Should be fixed in vNext.)
std/diagnostics/syserr/syserr.errcat/syserr.errcat.nonvirtuals/default_ctor.pass.cpp:1 FAIL

https://github.com/llvm/llvm-project/blob/master/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.nonvirtuals/default_ctor.pass.cpp

/* constexpr */ error_category() noexcept { // TRANSITION, ABI

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions