[PATCH] Fix source range of defaulted/deleted member declarations

Eli Bendersky eliben at google.com
Mon Mar 23 12:43:14 PDT 2015


================
Comment at: lib/Parse/ParseCXXInlineMethods.cpp:73
@@ -72,3 +72,3 @@
     bool Delete = false;
     SourceLocation KWLoc;
     if (TryConsumeToken(tok::kw_delete, KWLoc)) {
----------------
rnk wrote:
> Any reason we can't save Tok.getEndLoc() here? Then we don't have to hardcode the lengths of delete and default.
Great suggestion, thanks. Done

================
Comment at: lib/Parse/ParseCXXInlineMethods.cpp:80
@@ -79,1 +79,3 @@
       Delete = true;
+      if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
+        // The end of this decl has to point to the end of the 'delete' keyword
----------------
rnk wrote:
> This doesn't do the right thing for function templates, which the only case where this dyn_cast can fail. I think you can write a templated constructor and default it. =P A robust way to do this might be:
>   auto *FD = dyn_cast<FunctionDecl>(FnD);
>   FD = FD ? FD : cast<FunctionTemplateDecl>(FnD)->getTemplatedDecl();
>   FD->setRangeEnd(KWEndLoc);
Reid, I may be missing something here, do you mean something like:

struct Foot {
  template <typename T>
  Foot &operator=(const T& Other) = default;
};

I don't think this is actually valid. The standard says in 8.4.2:

"A function that is explicitly defaulted shall ... have the same declared function type (except for possibly differing ref-qualifiers and except that in the case of a copy constructor or copy assignment operator, the parameter type may be “reference to non-const T”, where T is the name of the member function’s class) as if it had been implicitly declared,
and"

And indeed Clang complains:


    error: only special member functions may be defaulted
       Foot &operator=(const T& Other) = default;

http://reviews.llvm.org/D8465

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list