[PATCH] D12686: Add support for GCC's '__auto_type' extension.

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 13 12:51:51 PDT 2015


thakis added inline comments.

================
Comment at: test/SemaCXX/auto-type-from-cxx.cpp:14
@@ +13,3 @@
+  auto _ = [](__auto_type f) {}; // expected-error {{'__auto_type' not allowed in lambda parameter}}
+  __auto_type g = 2;
+  struct BitField { int field:2; };
----------------
comex wrote:
> thakis wrote:
> > comex wrote:
> > > thakis wrote:
> > > > Shouldn't this say "warning: __auto_type is a gnu extension" (since this uses -std=c++14, not -std=gnu++14)?
> > > Hmm... when I added `ext_auto_type` to the .td, I didn't notice the difference between Extension and ExtWarn.  Since the patch currently uses Extension, it won't warn by default, but will with `-pedantic`, `-Wgnu`, or `-Wgnu-auto-type`.  The C test uses `-pedantic` so it gets the warning.
> > > 
> > > Is there an explicit policy on which extensions should be ExtWarn?  Looking at the rest of that file, ExtWarns seem to be mostly either (a) standardized extensions (which will warn if `-std` is too early) and (b) 'extensions' that are more like "Clang will accept your buggy code" than features.  Most GNU extensions are just Extension, so I think it makes sense to do the same for `__auto_type`.
> > > 
> > > I could update the C++ test to add `-pedantic`, but arguably it makes more sense to test the fact that the warning is not emitted by default.
> > I'm not sure either. `typeof` warns with -std=c++14 but not with -std=gnu++14. From a user perspective, this makes sense to me: I want to write standard c++ and I want the compiler to help me with that, but I don't want to get all the pedantic warnings that -pedantic entails. For example, consider using clang-cl to build Windows code, and wanting MSVC to be able to build said Windows code too. (This can of course go wrong with standard C++ too, but in that case I'm running into MSVC bugs which will eventually be fixed.) So if it's possible to match how typeof works, I think that'd be good. If it's not possible, this wouldn't be the only GNU extension allowed in -std=c++14 mode though, so it's not a big thing.
> As far as I can tell, `typeof` doesn't warn at all.  In standard mode it's an *error* because `typeof` is treated as a normal identifier (so that code that uses it as such doesn't break), but if you use the reserved-namespace keyword `__typeof`, there is no warning even with `-Weverything`.
Ah, ok. That's ok as-is then. It'd be nice if there was something that warning on GNU extensions, but that's independent of this patch :-)


http://reviews.llvm.org/D12686





More information about the cfe-commits mailing list