https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80390
Bug ID: 80390 Summary: std::pair of aligned type gives bogus warning Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: m...@sven-woop.de Target Milestone: --- The following code gives a weird warning regarding using a wrong version of ::new for the aligned type. As this code does not do any allocations, and the std::pair struct should inherit the alignment from its members this code should be fine. Code: ------ #include <utility> struct alignas(32) AlignedStruct { int a; }; std::pair<AlignedStruct,AlignedStruct> my_make_pair(const AlignedStruct& p0, const AlignedStruct& p1) { return std::make_pair(p0,p1); } Command line: -------------- g++ -Wall -o test.o -c test.cpp Output: -------- In file included from /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/move.h:54:0, from /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/stl_pair.h:59, from /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/utility:70, from test.cpp:1: /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits: In substitution of \u2018template<class _Tp, class _Arg, class> static std::true_type std::__do_is_direct_constructible_impl::__test(int) [with _Tp = AlignedStruct; _Arg = const AlignedStruct&; <template-parameter-1-3> = <missing>]\u2019: /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:987:41: required from \u2018struct std::__is_direct_constructible_impl<AlignedStruct, const AlignedStruct&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:143:12: required from \u2018struct std::__and_<std::is_destructible<AlignedStruct>, std::__is_direct_constructible_impl<AlignedStruct, const AlignedStruct&> >\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:991:12: required from \u2018struct std::__is_direct_constructible_new_safe<AlignedStruct, const AlignedStruct&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:1073:12: required from \u2018struct std::__is_direct_constructible_new<AlignedStruct, const AlignedStruct&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:1081:12: [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ] /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:1132:12: required from \u2018struct std::is_constructible<AlignedStruct, const AlignedStruct&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:143:12: required from \u2018struct std::__and_<std::is_constructible<AlignedStruct, const AlignedStruct&>, std::is_constructible<AlignedStruct, const AlignedStruct&> >\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/stl_pair.h:101:45: required from \u2018static constexpr bool std::_PCC<<anonymous>, _T1, _T2>::_ConstructiblePair() [with _U1 = AlignedStruct; _U2 = AlignedStruct; bool <anonymous> = true; _T1 = AlignedStruct; _T2 = AlignedStruct]\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/stl_pair.h:245:35: required by substitution of \u2018template<class _U1, class _U2, typename std::enable_if<(_ConstructiblePair<_U1, _U2>() && _ImplicitlyConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<AlignedStruct, AlignedStruct>::pair(const AlignedStruct&, const AlignedStruct&) [with _U1 = AlignedStruct; _U2 = AlignedStruct; typename std::enable_if<(_ConstructiblePair<_U1, _U2>() && _ImplicitlyConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = <missing>]\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/stl_pair.h:524:14: required from \u2018constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = const AlignedStruct&; _T2 = const AlignedStruct&; typename std::__decay_and_strip<_T2>::__type = AlignedStruct; typename std::__decay_and_strip<_Tp>::__type = AlignedStruct]\u2019 test.cpp:8:30: required from here /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:976:18: note: uses \u2018void* operator new(long unsigned int)\u2019, which does not have an alignment parameter = decltype(::new _Tp(declval<_Arg>()))> ^~~~~~~~~~~~~~~~~~~~~~~~~~ /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:976:18: note: use \u2018-faligned-new\u2019 to enable C++17 over-aligned new support /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits: In substitution of \u2018template<class _Tp, class _Arg, class> static std::true_type std::__do_is_direct_constructible_impl::__test(int) [with _Tp = AlignedStruct; _Arg = const AlignedStruct&&; <template-parameter-1-3> = <missing>]\u2019: /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:987:41: required from \u2018struct std::__is_direct_constructible_impl<AlignedStruct, const AlignedStruct&&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:143:12: required from \u2018struct std::__and_<std::is_destructible<AlignedStruct>, std::__is_direct_constructible_impl<AlignedStruct, const AlignedStruct&&> >\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:991:12: required from \u2018struct std::__is_direct_constructible_new_safe<AlignedStruct, const AlignedStruct&&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:1073:12: required from \u2018struct std::__is_direct_constructible_new<AlignedStruct, const AlignedStruct&&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:1081:12: required from \u2018struct std::__is_direct_constructible<AlignedStruct, const AlignedStruct&&>\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:1121:12: [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ] /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:143:12: required from \u2018struct std::__and_<std::is_constructible<AlignedStruct, const AlignedStruct&&>, std::__and_<std::is_convertible<const AlignedStruct&, AlignedStruct>, std::is_convertible<const AlignedStruct&, AlignedStruct> > >\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:148:12: required from \u2018struct std::__and_<std::is_constructible<AlignedStruct, const AlignedStruct&>, std::is_constructible<AlignedStruct, const AlignedStruct&&>, std::__and_<std::is_convertible<const AlignedStruct&, AlignedStruct>, std::is_convertible<const AlignedStruct&, AlignedStruct> > >\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/stl_pair.h:150:12: required from \u2018static constexpr bool std::_PCC<<anonymous>, _T1, _T2>::_MoveCopyPair() [with bool __implicit = true; _U1 = const AlignedStruct&; _U2 = AlignedStruct; bool <anonymous> = true; _T1 = AlignedStruct; _T2 = AlignedStruct]\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/stl_pair.h:298:36: required by substitution of \u2018template<class _U1, typename std::enable_if<_MoveCopyPair<true, _U1, AlignedStruct>(), bool>::type <anonymous> > constexpr std::pair<AlignedStruct, AlignedStruct>::pair(_U1&&, const AlignedStruct&) [with _U1 = const AlignedStruct&; typename std::enable_if<_MoveCopyPair<true, _U1, AlignedStruct>(), bool>::type <anonymous> = <missing>]\u2019 /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/bits/stl_pair.h:524:14: required from \u2018constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = const AlignedStruct&; _T2 = const AlignedStruct&; typename std::__decay_and_strip<_T2>::__type = AlignedStruct; typename std::__decay_and_strip<_Tp>::__type = AlignedStruct]\u2019 test.cpp:8:30: required from here /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:976:18: note: uses \u2018void* operator new(long unsigned int)\u2019, which does not have an alignment parameter /home/swoop/projects/gcc/latest/usr/local/include/c++/7.0.1/type_traits:976:18: note: use \u2018-faligned-new\u2019 to enable C++17 over-aligned new support