llvm / llvm/llvm-project

Access checks and copy elision before c++17

Open
#161,858 3 comments 1 reaction 0 assignees View on GitHub
clang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

We claim to support guaranteed copy elision in C++03, but we still perform access checks for copy constructors (before c++17)
https://godbolt.org/z/WPEh8e94c

```cpp
class S {
public:
S(int, int);

// private:
S(const S &);
};

S s = S(0, 0);
```

If we make the constructor public, RVO is performed https://godbolt.org/z/WPEh8e94c

Aditionally `__cpp_guaranteed_copy_elision` is not set even if the documentation claim it should be
https://clang.llvm.org/docs/LanguageExtensions.html#id34

Maybe the documentation is just wrong.

Contributor guide

Open the contributing guide

Research direction

Start with the reduced C++ example and the linked Godbolt results, comparing behavior before C++17 with and without an accessible copy constructor. Then inspect the Language Extensions documentation at the linked guaranteed-copy-elision section and the reported __cpp_guaranteed_copy_elision definition. Done means the access-check behavior and feature-test macro agree with the documented support, or the documentation is corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.