LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 26961 - Enumeration type std::pointer_safety incorrectly implemented as a struct
Summary: Enumeration type std::pointer_safety incorrectly implemented as a struct
Status: RESOLVED FIXED
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: 3.8
Hardware: PC All
: P normal
Assignee: Eric Fiselier
URL:
Keywords: ABI
Depends on:
Blocks:
 
Reported: 2016-03-16 07:09 PDT by ionelpopescu97
Modified: 2017-01-04 19:30 PST (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ionelpopescu97 2016-03-16 07:09:48 PDT
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 <memory>

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.
Comment 1 Yuanfang Chen 2016-03-16 09:40:46 PDT
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.
Comment 2 Eric Fiselier 2016-03-16 13:46:44 PDT
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.
Comment 3 Eric Fiselier 2017-01-04 19:30:36 PST
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.