This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] fix libstdc++/56012 - narrowing conversion in std::atomic_flag


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]