[cfe-dev] Objective-C++11: concerns about adding static_assert support to @interface / @implementation?

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Sat Mar 9 10:24:10 PST 2019


On Fri, Mar 8, 2019 at 8:10 PM Erik Pilkington
<erik.pilkington at gmail.com> wrote:
>
>
>
> > On Mar 8, 2019, at 4:51 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
> >
> > On Fri, Mar 8, 2019 at 11:52 AM Nico Weber <thakis at chromium.org> wrote:
> >>
> >> On Fri, Mar 8, 2019 at 11:23 AM Aaron Ballman <aaron at aaronballman.com> wrote:
> >>>
> >>> On Fri, Mar 8, 2019 at 11:20 AM Nico Weber via cfe-dev
> >>> <cfe-dev at lists.llvm.org> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> I'm trying to enable -Wextra-semi in Chromium. I'm almost there; the last remaining issue is that we have a macro THREAD_CHECKER(name) that expands to nothing in release builds but to `ThreadChecker name` in debug builds. It's supposed to be used like
> >>>>
> >>>> class C {
> >>>>  THREAD_CHECKER(checker_);
> >>>> };
> >>>>
> >>>> And then in the implementation, you do CHECK_CALLED_ON_VALID_THREAD(checker_); which again does nothing in release builds but calls a method on checker_ in debug builds.
> >>>>
> >>>> Since this is a declaration, this triggers -Wextra-semi. I figured the way to spell the usual `do {} while (0)` you tag on the end of a statement macro to silence this warning could be `static_assert(1, "")`, so I changed THREAD_CHECKER() to expand to that in release builds instead of nothing.
> >>>>
> >>>> This works beautifully, but Objective-C interfaces don't support static_assert()s as I have learned. So I'd like to add support for that.
> >>>
> >>> Do they support _Static_assert() instead (the C11 spelling)
> >>
> >>
> >> No.
> >
> > Good to know!
> >
> > I'd also like to see _Static_assert() supported in Objective-C and
> > static_assert() supported in Objective-C++; I think they'd be useful.
> > However, I'm not certain of the relationship between ObjC/C++ versions
> > and the language standard version of C/C++ and whether there might be
> > concerns there.
>
>
> My understanding is that we try to be as compatible as possible with the base language, so -xobjective-c++ -std=c++11 should behave just like -std=c++11, but also have objective-c stuff. Thats what we do in general with static_assert/_Static_assert here too, its just that for some reason we don’t parse them in this context.

Ah, nice to know, thank you Erik. Then yeah, count me as a +1 for
supporting this.

~Aaron

>
> Erik
>
>
> >
> > ~Aaron
>



More information about the cfe-dev mailing list