Fix Q_TOSTR(3) with GCC when it's called with first parameter
being const.
One one hand this is trivial, on the other - it's a rather
weird construct, so I'd rather get some feedback.
Differential D21766
Fix Q_TOSTR(3) when called with first parameter being const trasz on Sep 23 2019, 3:22 PM. Authored by Tags None Referenced Files
Subscribers
Details Fix Q_TOSTR(3) with GCC when it's called with first parameter One one hand this is trivial, on the other - it's a rather
Diff Detail
Event TimelineComment Actions Ok, I researched this a little bit. It looks like Q_BT is only used in two places, neither of which wants a const type. (Well, three places, 3rd being Q_TC(), but... it's easy enough to just use __typeof directly there.) I think this problem is specific to ancient GCC4. I cannot reproduce it on GCC 6.3 or newer. If it were a newer GCC problem, we could use a C11 _Generic() construct to de-const the reference variable. But newer GCC already de-consts in __typeof(). (Source: https://godbolt.org/z/m-ye3e ) So I think I'd elect to use the same weird hack and just move it to the macro definition rather than this invocation. E.g., #if __GNUC__ > 4 || defined(__clang__) #define Q_BT(q) __typeof(q) #else /* Ancient GCC hack to de-const, remove when GCC4 is removed. */ #define Q_BT(q) __typeof(1 * q) #endif #define Q_TC(q, v) ((__typeof(q))(v)) Comment Actions For some reason the '#if GNUC > 4' doesn't seem to work for RISC-V tinderbox builds - they fail as before. It does fix the situation for in-tree GCC though. TBH I don't think narrowing it down is worth it.
|