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

Nicholas Allegra via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 10 11:27:04 PST 2015


comex added a comment.

Addressed comments.  Thanks, rsmith!


================
Comment at: lib/Sema/SemaType.cpp:3756-3760
@@ -3743,2 +3755,7 @@
           }
+        } else if (D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto_type) {
+          S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
+                 diag::err_auto_not_allowed)
+            << 2 << 13 << D.getDeclSpec().getSourceRange();
+          D.setInvalidType(true);
         }
----------------
rsmith wrote:
> Please deal with this in the "checking for auto" block at the top rather than repeating the diagnostic code here with magic numbers; maybe change
> 
>   (!SemaRef.getLangOpts().CPlusPlus11 || !D.isFunctionDeclarator())) {
> 
> to
> 
>   (!SemaRef.getLangOpts().CPlusPlus11 || !D.isFunctionDeclarator() || D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto_type)) {
> 
> up there.
For the sake of clarity, I removed that whole bit from the if condition instead and moved the C++11 test down to where it sets `Error`.  Two bits of fallout from this:
- `typedef decltype(auto) f();` gets diagnosed there rather than later with a different error; I updated the test, since both errors seem reasonable.
- A bug is fixed where definitions like `auto f() { return 5; }` were not being caught with `-std=c++14 -Wc++98-compat`.  I updated the c++98-compat test to add this case.


http://reviews.llvm.org/D12686





More information about the cfe-commits mailing list