[cfe-dev] std::pair not trivially copyable?
Robinson, Paul via cfe-dev
cfe-dev at lists.llvm.org
Tue Aug 25 05:51:51 PDT 2020
We had someone trip over a case that reduces to this:
F:\scratch>type tc6347.cpp
#include <utility>
std::pair<unsigned, bool> data[10];
void bar() {
for (const auto item : data)
(void)item.first;
}
F:\scratch>%wo%\clang -c -Wall tc6347.cpp
tc6347.cpp:4:19: warning: loop variable 'item' of type 'const std::pair<unsigned
int, bool>' creates a copy from type 'const std::pair<unsigned int, bool>'
[-Wrange-loop-construct]
for (const auto item : data)
^
tc6347.cpp:4:8: note: use reference type 'const std::pair<unsigned int, bool> &'
to prevent copying
for (const auto item : data)
^~~~~~~~~~~~~~~~~
&
1 warning generated.
F:\scratch>
This used to compile cleanly. It turns out that the diagnostic
used to be suppressed for POD types, and now it is suppressed for
trivially-copyable types.
So... a std::pair of two scalars is not trivially copyable?
I'd have thought it would be, but then C++ is full of surprises.
Thanks,
--paulr
More information about the cfe-dev
mailing list