[llvm-bugs] [Bug 46776] New: bogus -Wmissing-braces for CTAD deduced aggregate with inherited base

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jul 19 12:22:01 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46776

            Bug ID: 46776
           Summary: bogus -Wmissing-braces for CTAD deduced aggregate with
                    inherited base
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: wjwray at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Combination of aggregate CTAD and inheritance makes -Wmissing-braces wrong.

For example, take a tuple class with the usual CTAD:
https://wandbox.org/permlink/USZGcupYvTtP8D6D

  template <typename...> struct tuple;
  template <typename... T> tuple(T...) -> tuple<T...>;

Implement it as an aggregate, by explicit specializations:

  template <> struct tuple<> {};
  template <typename A> struct tuple<A> {A a;};
  template <typename A, typename B> struct tuple<A,B> {A a; B b;};
  ... & etc.

Now, 'tie' is usually implemented as a helper 'make' function tie(...) 
Instead, implement tie as a class inheriting from tuple, with CTAD

  template <typename... T> struct tie : tuple<T...> {};
  template <typename... T> tie(T&...) -> tie<T&...>;

along with an extra tuple CTAD converting from tie to tuple

  template <typename... T> tuple(tie<T...>) -> tuple<T...>;

Now, usage of tie looks like this:

  bool up = true;
  tuple t = tie{up};

warning: suggest braces around initialization of subobject [-Wmissing-braces]
tuple t = tie{up};
              ^~
              { }
1 warning generated.

However, this warning is incorrect here -
adding the suggested braces breaks the CTAD deduction.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200719/62447339/attachment.html>


More information about the llvm-bugs mailing list