https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97740
Bug ID: 97740 Summary: Weird error message about accessing a private member of my own class inside of std::string_view inside of constexpr Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: markus.boeck02 at gmail dot com Target Milestone: --- Created attachment 49513 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49513&action=edit Reproduction of the bug. Simply compile with -std=c++17 I want to apologize for the code you are about to see already. I am one of those people who likes to constexpr and templates at times. In one of my recent code that does some constexpr string parsing and validation I encountered a very very weird error message: /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/string_view: In instantiation of 'cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)> [with auto:7 = {const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&}]': /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/type_traits:2506:26: required by substitution of 'template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>; _Args = {const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&}]' /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/type_traits:2517:55: required from 'struct std::__result_of_impl<false, false, cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>, const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&>' /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/type_traits:138:12: recursively required by substitution of 'template<class _Result, class _Ret> struct std::__is_invocable_impl<_Result, _Ret, true, std::__void_t<typename _CTp::type> > [with _Result = std::__invoke_result<cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>, const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&>; _Ret = void]' /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/type_traits:138:12: required from 'struct std::__and_<std::__is_invocable_impl<std::__invoke_result<cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>, const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&>, void, true, void>, std::__call_is_nothrow<std::__invoke_result<cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>, const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&>, cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>, const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&> >' /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/type_traits:2979:12: required from 'struct std::is_nothrow_invocable<cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>, const std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > >&>' /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/tuple:1715:37: required from 'constexpr const bool std::__unpack_std_tuple<template<class _Fn, class ... _ArgTypes> struct std::is_nothrow_invocable, cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>, const std::tuple<std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > > >&>' /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/tuple:1730:14: required from 'constexpr decltype(auto) std::apply(_Fn&&, _Tuple&&) [with _Fn = cld::detail::CommandLine::parseOptions<cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>, {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}>::<lambda(auto:7&& ...)>; _Tuple = const std::tuple<std::pair<cld::detail::CommandLine::Pointer<(& detail::INCLUDESbind0)>, std::in_place_type_t<std::basic_string_view<char, std::char_traits<char> > > > >&]' <source>:456:36: required from 'constexpr auto cld::detail::CommandLine::parseOptions(std::string_view, cld::CLIMultiArg) [with T = cld::detail::CommandLine::Pack<detail::INCLUDESarg0, detail::INCLUDESarg1, detail::INCLUDESarg2>; auto& ...args = {detail::INCLUDESbind0, std::in_place_type<std::basic_string_view<char, std::char_traits<char> > >}; std::string_view = std::basic_string_view<char>]' <source>:502:62: required from here /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/string_view:287:34: error: 'char cld::Constexpr::basic_fixed_string<char, 7>::m_data [7]' is private within this context 287 | return basic_string_view{_M_str + __pos, __rlen}; | ~~~~~~~^~~~~~~ <source>:18:5: note: declared private here 18 | T m_data[N] = {}; | I tried to create a minimum reproducible from scratch but failed to so. Instead I now used my code and tried to minimize that as much as possible which sadly still amounts to 500 lines of code but does reproduce the issue. I have attached the file. To my knowledge the code is correct and clang and MSVC compile it without issues. Changing m_data in basic_fixed_string from private to public makes the build succeed. Every version of GCC 8 to trunk fail with the same error. GCC 7 instead has an internal compiler error. Alternatively see this compiler explorer link: https://godbolt.org/z/snnfo7