<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang++ fails to instantiate std::optional if type has a enum class field"
   href="https://bugs.llvm.org/show_bug.cgi?id=50904">50904</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang++ fails to instantiate std::optional if type has a enum class field
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>florin@signbit.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using clang trunk:

   Debian clang version 13.0.0-++20210619101720+e1adf90826a5-1~exp1
   Target: x86_64-pc-linux-gnu
   Thread model: posix
   InstalledDir: /usr/bin
   Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
   Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
   Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
   Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
   Candidate multilib: .;@m64
   Selected multilib: .;@m64

The following program fails to compile:

#include <optional>

class Bar
{
public:
   struct Foo
   {
#if WANT_TO_SEE_IT_FAIL
      enum class Toast
      {
         Alpha,
         Beta,
         Gamma
      };

      Toast aToast = Toast::Beta;
#endif

      int someInt;
   };

   std::optional<Foo> theFoo;
};

int main()
{
   Bar aBar;

   aBar.theFoo = std::make_optional<Bar::Foo>();

   return 0;
}

$ clang++-13 -std=c++17 -DWANT_TO_SEE_IT_FAIL test_std_optional_fail.cpp      
(main)clang_limitations
test_std_optional_fail.cpp:29:18: error: no matching function for call to
'make_optional'
   aBar.theFoo = std::make_optional<Bar::Foo>();
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/optional:1269:5:
note: candidate template ignored: requirement 'is_constructible_v<Bar::Foo>'
was not satisfied [with _Tp = Bar::Foo, _Args = <>]
    make_optional(_Args&&... __args)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/optional:1261:5:
note: candidate function template not viable: requires single argument '__t',
but no arguments were provided
    make_optional(_Tp&& __t)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/optional:1277:5:
note: candidate function template not viable: requires at least argument
'__il', but no arguments were provided
    make_optional(initializer_list<_Up> __il, _Args&&... __args)
    ^
1 error generated.

If we don't define WANT_TO_SEE_IT_FAIL then the program compiles.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>