]> granicus.if.org Git - clang/commitdiff
Check that this cannot be used in a default argument. Happily, it was already implemented
authorDouglas Gregor <dgregor@apple.com>
Mon, 3 Nov 2008 22:47:57 +0000 (22:47 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 3 Nov 2008 22:47:57 +0000 (22:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58649 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/default2.cpp

index 9c1e4a949fa75dd027c3c6e1d1c3993da1535ce0..4a2f0b43f63db6d37a7035bb664f34292015850f 100644 (file)
@@ -84,8 +84,13 @@ namespace {
                        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;
   }
index d3e999c34c6d3f3abbfaaa80c8cadc3848dd478d..89eb4671d9326acb65d1a72f8be653bba7e830b3 100644 (file)
@@ -36,3 +36,7 @@ void nondecl(int (*f)(int x = 5)) // {expected-error {{default arguments can onl
   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}}
+};