This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] fix libstdc++/56012 - narrowing conversion in std::atomic_flag
- From: Daniel Krügler <daniel dot kruegler at gmail dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Andrew MacLeod <amacleod at redhat dot com>, Richard Henderson <rth at redhat dot com>, Benjamin Kosnik <bkoz at redhat dot com>
- Date: Thu, 17 Jan 2013 08:53:20 +0100
- Subject: Re: [patch] fix libstdc++/56012 - narrowing conversion in std::atomic_flag
- References: <CAH6eHdQvPmb=p9FR1xVEmAtCiKRQZ5yzX3BHyHKqgH=TNHpRkw@mail.gmail.com>
2013/1/17 Jonathan Wakely <jwakely.gcc@gmail.com>:
> This fixes a regression since 4.6 when -Wsystem-headers is used. The
> initialization of the __atomic_flag_base base class has a narrowing
> conversion from int (the macro) to either bool or unsigned char. The
> patch fixes it by calling a constexpr function which implicitly
> converts the value to the return type instead of doing the conversion
> inside a braced-init-list. Doing that requires naming the return
> type, so I defined a new typedef for to avoid duplicating the
> preprocessor conditional. The patch also adds a missing assignment
> operator in atomic<bool>.
>
> PR libstdc++/56012
> * include/bits/atomic_base.h (atomic_flag): Fix narrowing conversion.
> * testsuite/29_atomics/atomic/operators/56012.cc: New.
>
> PR libstdc++/56011
> * include/std/atomic (atomic<bool>::operator=(bool) volatile): Add
> missing overload.
> * testsuite/29_atomics/atomic/operators/56011.cc: New.
>
> Tested x86_64-linux, it's a regression so I want to commit it to the
> trunk and 4.7 branch, any objections from the atomics experts?
Isn't here a typedef missing:
+ /* The target's "set" value for test-and-set may not be exactly 1. */
+#if __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1
+ typedef bool __atomic_flag_data_type;
+#else
+ unsigned char __atomic_flag_data_type;
+#endif
I would expect that this looked like:
+ /* The target's "set" value for test-and-set may not be exactly 1. */
+#if __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1
+ typedef bool __atomic_flag_data_type;
+#else
+ typedef unsigned char __atomic_flag_data_type;
+#endif
- Daniel