public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98620] New: SFINAE code in class specialization generate warnings
@ 2021-01-11 13:42 m.cencora at gmail dot com
  2021-01-11 15:01 ` [Bug c++/98620] SFINAE code in class specialization generates warnings redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: m.cencora at gmail dot com @ 2021-01-11 13:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98620

            Bug ID: 98620
           Summary: SFINAE code in class specialization generate warnings
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.cencora at gmail dot com
  Target Milestone: ---

Following code compiled in any gcc>=5, C++11 or higher, and
-Wmissing-field-initializers generate compiler warning:

g++ -std=c++20 -Wmissing-field-initializers

#include <type_traits>

template <typename T>
struct TmpArray
{
   T arr[1];
};

template <typename Src, typename Dst, typename = void>
struct is_non_narrowing_conversion : std::false_type
{};

template <typename Src, typename Dst>
struct is_non_narrowing_conversion<
    Src, Dst,
    decltype(void(TmpArray<Dst>{{ std::declval<Src>() }}))
> : std::true_type
{};

struct mystruct
{
    int a;
    void * b;
};


void test_nok()
{
    is_non_narrowing_conversion<int&, mystruct>::type v;
}

SFINAE is used here only to detect if a code compiles, and code inside the
decltype should not generate warnings.

Also this is inconsistent, because when SFINAE is used in function template the
warning is not generated:
template <typename Dst, typename Src>
auto is_non_narrowing_conversion_func_impl(Src&&, int)
   -> decltype((TmpArray<Dst>{{ std::declval<Src>() }}, std::true_type{}));

template <typename Dst, typename Src>
auto is_non_narrowing_conversion_func_impl(Src&&, ...)
   -> std::false_type;

template <typename Src, typename Dst>
using is_non_narrowing_conversion_v2 =
decltype(is_non_narrowing_conversion_func_impl<Dst>(std::declval<Src>(), 0));

void test_ok()
{
    is_non_narrowing_conversion_v2<int&, mystruct> v;
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-12  3:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 13:42 [Bug c++/98620] New: SFINAE code in class specialization generate warnings m.cencora at gmail dot com
2021-01-11 15:01 ` [Bug c++/98620] SFINAE code in class specialization generates warnings redi at gcc dot gnu.org
2021-01-11 15:24 ` mpolacek at gcc dot gnu.org
2021-01-11 23:19 ` mpolacek at gcc dot gnu.org
2021-01-12  3:31 ` cvs-commit at gcc dot gnu.org
2021-01-12  3:32 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).