Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration type std::pointer_safety incorrectly implemented as a struct #27335

Closed
llvmbot opened this issue Mar 16, 2016 · 3 comments
Closed
Labels
ABI Application Binary Interface bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 16, 2016

Bugzilla Link 26961
Resolution FIXED
Resolved on Jan 04, 2017 19:30
Version 3.8
OS All
Reporter LLVM Bugzilla Contributor
CC @hfinkel,@mclow,@yuanfang-chen

Extended Description

The C++11 standard defines pointer_safety as:
enum class pointer_safety { relaxed, preferred, strict };

But, currently pointer_safety is implemented as a struct.

This causes that the following test to fail, because it is initialized by a constructor that takes an int:

#include

int main()
{
std::pointer_safety d ;
d = std::get_pointer_safety();

return 0;

}

test.cpp:5:25: error: no matching constructor for initialization of 'std::pointer_safety'
std::pointer_safety d ;
^
/usr/include/c++/v1/memory:5406:5: note: candidate constructor not viable: requires single argument '__v', but no arguments were provided
pointer_safety(__lx __v) : _v(__v) {}
^
/usr/include/c++/v1/memory:5394:25: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
struct _LIBCPP_TYPE_VIS pointer_safety
^
/usr/include/c++/v1/memory:5394:25: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided
1 error generated.

@yuanfang-chen
Copy link
Collaborator

http://clang.llvm.org/cxx_status.html

Minimal support for garbage collection and reachability-based leak detection N2670 N/A (2)

it is not implemented in clang for reasons stated there.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 16, 2016

So libc++ clearly implemented this incorrectly. My guess is that it was done before compilers supported enum classes.

Changing from using a struct to using an enum class is ABI breaking for users and for the dylib which exports std::get_pointer_safety.

Fixing this will probably be a pretty low priority.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 5, 2017

Alright. Fixed in v4.0 by r291059 and r291046. The two relevant changes are:

  1. libc++ now implements std::pointer_safety as an enum type in ABI v2.
  2. The fallback struct type now provides a default constructor.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI Application Binary Interface bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants