This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fix std::optional-related type deduction
AbandonedPublic

Authored by ianloic on Apr 4 2023, 12:35 PM.

Details

Reviewers
ldionne
philnik
EricWF
Group Reviewers
Restricted Project
Summary

When clang a constructor invocation where there are single-argument
constructors that take either std::optional or some other type the
checks in _CheckOptionalArgsConstructor fail becaues that helper tries
(and fails) to take an rvalue-reference to void.

A simple example is here: https://godbolt.org/z/bPdzYfcnv
This works just fine with other C++ standard library implementations.

This change uses std::add_rvalue_reference_t<T> rather than T&& to avoid
the compilation error.

This fixes bug https://github.com/llvm/llvm-project/issues/61692 and
maybe https://github.com/llvm/llvm-project/issues/48959.

Diff Detail

Event Timeline

ianloic created this revision.Apr 4 2023, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 12:35 PM
ianloic requested review of this revision.Apr 4 2023, 12:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 12:35 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
phosek added a subscriber: phosek.
phosek added inline comments.
libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ambigous_constructor.pass.cpp
30

Nit: please make sure there's a newline at the end of the file.

ianloic updated this revision to Diff 510906.Apr 4 2023, 1:03 PM

Added trailing blank line.

ianloic marked an inline comment as done.Apr 4 2023, 1:05 PM
philnik requested changes to this revision.Apr 4 2023, 2:30 PM
philnik added a subscriber: philnik.

This changes behaviour, in a not necessarily conforming way. I don't know why other standard library implementations accept your construct while libc++ doesn't, but this is definitely not the right fix. Interestingly, implementing the constructor yourself works with one standard but not the other: https://godbolt.org/z/GKKGP46fs, and both bug reports use std::string. Maybe there lies the real issue? You should probably reduce the reproducer further to find out where the problem actually is.

libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ambigous_constructor.pass.cpp
20–21

Please don't use using in the tests.

34

Please don't use reserved identifiers in the tests.

This revision now requires changes to proceed.Apr 4 2023, 2:30 PM
ianloic updated this revision to Diff 510936.Apr 4 2023, 2:59 PM

Reduce test case, address comments.

ianloic marked 2 inline comments as done.Apr 4 2023, 4:40 PM

This changes behaviour, in a not necessarily conforming way. I don't know why other standard library implementations accept your construct while libc++ doesn't, but this is definitely not the right fix. Interestingly, implementing the constructor yourself works with one standard but not the other: https://godbolt.org/z/GKKGP46fs, and both bug reports use std::string. Maybe there lies the real issue? You should probably reduce the reproducer further to find out where the problem actually is.

I can make a test-case without std::string: https://godbolt.org/z/Edr58onYP
but I'm still working on understanding more deeply what's going on with it. I'm trying to reduce the std::optional implementation to find where it's really going wrong.

libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ambigous_constructor.pass.cpp
20–21

No worries, I was copying the style of a neighboring test.

ianloic updated this revision to Diff 510975.Apr 4 2023, 5:30 PM
ianloic marked an inline comment as done.

A different approach

ianloic edited the summary of this revision. (Show Details)Apr 5 2023, 10:27 AM
EricWF requested changes to this revision.Apr 5 2023, 1:13 PM
EricWF added a subscriber: EricWF.

I think this is a bandaid over a bigger clang bug.

I don't want to accept a patch to placate clang here until we know what's actually going on.

This revision now requires changes to proceed.Apr 5 2023, 1:13 PM
ianloic abandoned this revision.Apr 11 2023, 11:54 AM

The underling clang issue has been fixed.