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 31916 - [c++1z] std::visit does not accept visitors which require non-const lvalue references
Summary: [c++1z] std::visit does not accept visitors which require non-const lvalue re...
Status: RESOLVED FIXED
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: unspecified
Hardware: PC All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-09 05:02 PST by Bruno Manganelli
Modified: 2017-02-09 13:02 PST (History)
3 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 Bruno Manganelli 2017-02-09 05:02:40 PST
The following snippet fails on clang with :
"static_assert failed "`std::visit` requires the visitor to be exhaustive."
Both gcc and vc++ accept non-const lvalue references.

#include <iostream>
#include <variant>

struct A { int x = 33; };

struct Visitor
{
    void operator()(A &node) { std::cout << node.x; }
};
int main() 
{  
   std::variant<A> var = A{};
   std::visit(Visitor{}, var);
}
Comment 1 Eric Fiselier 2017-02-09 13:02:26 PST
Fixed in r294612. Thanks for the report. I'll backport this fix into the 4.0 release.