Check that this cannot be used in a default argument. Happily, it was already implemented
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58649 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 9c1e4a9..4a2f0b4 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -84,8 +84,13 @@
VDecl->getName(), DefaultArg->getSourceRange());
}
- // FIXME: when Clang has support for member functions, "this"
- // will also need to be diagnosed.
+ // C++ [dcl.fct.default]p8:
+ // The keyword this shall not be used in a default argument of a
+ // member function.
+ // Note: this requirement is already diagnosed by
+ // Sema::ActOnCXXThis, because the use of "this" inside a default
+ // argument doesn't occur inside the body of a non-static member
+ // function.
return false;
}
diff --git a/test/SemaCXX/default2.cpp b/test/SemaCXX/default2.cpp
index d3e999c..89eb467 100644
--- a/test/SemaCXX/default2.cpp
+++ b/test/SemaCXX/default2.cpp
@@ -36,3 +36,7 @@
void (*f2)(int = 17) // {expected-error {{default arguments can only be specified}}}
= (void (*)(int = 42))f; // {expected-error {{default arguments can only be specified}}}
}
+
+class X {
+ void f(X* x = this); // expected-error{{invalid use of 'this' outside of a nonstatic member function}}
+};