r329493 - [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

Roman Lebedev via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 7 03:39:21 PDT 2018


Author: lebedevri
Date: Sat Apr  7 03:39:21 2018
New Revision: 329493

URL: http://llvm.org/viewvc/llvm-project?rev=329493&view=rev
Log:
[Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

Summary:
This has just bit me, so i though it would be nice to avoid that next time :)
Motivational case:
  https://godbolt.org/g/cq9UNk
Basically, it's likely to happen if you don't like shadowing issues,
and use `-Wshadow` and friends. And it won't be diagnosed by clang.

The reason is, these self-assign diagnostics only work for builtin assignment
operators. Which makes sense, one could have a very special operator=,
that does something unusual in case of self-assignment,
so it may make sense to not warn on that.

But while it may be intentional in some cases, it may be a bug in other cases,
so it would be really great to have some diagnostic about it...

Reviewers: aaron.ballman, rsmith, rtrieu, nikola, rjmccall, dblaikie

Reviewed By: rjmccall

Subscribers: EricWF, lebedev.ri, thakis, Quuxplusone, cfe-commits

Differential Revision: https://reviews.llvm.org/D44883

Added:
    cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp
    cfe/trunk/test/SemaCXX/warn-self-assign-field-builtin.cpp
    cfe/trunk/test/SemaCXX/warn-self-assign-field-overloaded.cpp
    cfe/trunk/test/SemaCXX/warn-self-assign-overloaded.cpp
Removed:
    cfe/trunk/test/SemaCXX/warn-self-assign.cpp
Modified:
    cfe/trunk/docs/ReleaseNotes.rst
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/member-init.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=329493&r1=329492&r2=329493&view=diff
==============================================================================
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Apr  7 03:39:21 2018
@@ -59,6 +59,12 @@ Improvements to Clang's diagnostics
   ``-Wno-c++98-compat-extra-semi``, so if you want that diagnostic, you need
   to explicitly re-enable it (e.g. by appending ``-Wextra-semi``).
 
+- ``-Wself-assign`` and ``-Wself-assign-field`` were extended to diagnose
+  self-assignment operations using overloaded operators (i.e. classes).
+  If you are doing such an assignment intentionally, e.g. in a unit test for
+  a data structure, the warning can be suppressed by adding ``*&`` to the
+  right-hand side or casting it to the appropriate reference type.
+
 Non-comprehensive list of changes in this release
 -------------------------------------------------
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=329493&r1=329492&r2=329493&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Apr  7 03:39:21 2018
@@ -10701,12 +10701,34 @@ static bool CheckForModifiableLvalue(Exp
 static void CheckIdentityFieldAssignment(Expr *LHSExpr, Expr *RHSExpr,
                                          SourceLocation Loc,
                                          Sema &Sema) {
+  if (Sema.inTemplateInstantiation())
+    return;
+  if (Sema.isUnevaluatedContext())
+    return;
+  if (Loc.isInvalid() || Loc.isMacroID())
+    return;
+  if (LHSExpr->getExprLoc().isMacroID() || RHSExpr->getExprLoc().isMacroID())
+    return;
+
   // C / C++ fields
   MemberExpr *ML = dyn_cast<MemberExpr>(LHSExpr);
   MemberExpr *MR = dyn_cast<MemberExpr>(RHSExpr);
-  if (ML && MR && ML->getMemberDecl() == MR->getMemberDecl()) {
-    if (isa<CXXThisExpr>(ML->getBase()) && isa<CXXThisExpr>(MR->getBase()))
-      Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;
+  if (ML && MR) {
+    if (!(isa<CXXThisExpr>(ML->getBase()) && isa<CXXThisExpr>(MR->getBase())))
+      return;
+    const ValueDecl *LHSDecl =
+        cast<ValueDecl>(ML->getMemberDecl()->getCanonicalDecl());
+    const ValueDecl *RHSDecl =
+        cast<ValueDecl>(MR->getMemberDecl()->getCanonicalDecl());
+    if (LHSDecl != RHSDecl)
+      return;
+    if (LHSDecl->getType().isVolatileQualified())
+      return;
+    if (const ReferenceType *RefTy = LHSDecl->getType()->getAs<ReferenceType>())
+      if (RefTy->getPointeeType().isVolatileQualified())
+        return;
+
+    Sema.Diag(Loc, diag::warn_identity_field_assign) << 0;
   }
 
   // Objective-C instance variables
@@ -11460,12 +11482,13 @@ static inline UnaryOperatorKind ConvertT
 }
 
 /// DiagnoseSelfAssignment - Emits a warning if a value is assigned to itself.
-/// This warning is only emitted for builtin assignment operations. It is also
-/// suppressed in the event of macro expansions.
+/// This warning suppressed in the event of macro expansions.
 static void DiagnoseSelfAssignment(Sema &S, Expr *LHSExpr, Expr *RHSExpr,
                                    SourceLocation OpLoc) {
   if (S.inTemplateInstantiation())
     return;
+  if (S.isUnevaluatedContext())
+    return;
   if (OpLoc.isInvalid() || OpLoc.isMacroID())
     return;
   LHSExpr = LHSExpr->IgnoreParenImpCasts();
@@ -12080,6 +12103,21 @@ ExprResult Sema::ActOnBinOp(Scope *S, So
 static ExprResult BuildOverloadedBinOp(Sema &S, Scope *Sc, SourceLocation OpLoc,
                                        BinaryOperatorKind Opc,
                                        Expr *LHS, Expr *RHS) {
+  switch (Opc) {
+  case BO_Assign:
+  case BO_DivAssign:
+  case BO_RemAssign:
+  case BO_SubAssign:
+  case BO_AndAssign:
+  case BO_OrAssign:
+  case BO_XorAssign:
+    DiagnoseSelfAssignment(S, LHS, RHS, OpLoc);
+    CheckIdentityFieldAssignment(LHS, RHS, OpLoc, S);
+    break;
+  default:
+    break;
+  }
+
   // Find all of the overloaded operators visible from this
   // point. We perform both an operator-name lookup from the local
   // scope and an argument-dependent lookup based on the types of

Modified: cfe/trunk/test/SemaCXX/member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-init.cpp?rev=329493&r1=329492&r2=329493&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-init.cpp Sat Apr  7 03:39:21 2018
@@ -101,7 +101,7 @@ namespace rdar14084171 {
   struct Sprite {
     Point location = Point(0,0); // expected-error {{no matching constructor for initialization of 'rdar14084171::Point'}}
   };
-  void f(Sprite& x) { x = x; }
+  void f(Sprite& x) { x = x; } // expected-warning {{explicitly assigning value of variable}}
 }
 
 namespace PR18560 {

Added: cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp?rev=329493&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-self-assign-builtin.cpp Sat Apr  7 03:39:21 2018
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -verify %s
+
+void f() {
+  int a = 42, b = 42;
+  a = a; // expected-warning{{explicitly assigning}}
+  b = b; // expected-warning{{explicitly assigning}}
+  a = b;
+  b = a = b;
+  a = a = a; // expected-warning{{explicitly assigning}}
+  a = b = b = a;
+
+  a *= a;
+  a /= a;
+  a %= a;
+  a += a;
+  a -= a;
+  a <<= a;
+  a >>= a;
+  a &= a; // expected-warning {{explicitly assigning}}
+  a |= a; // expected-warning {{explicitly assigning}}
+  a ^= a;
+}
+
+// Dummy type.
+struct S {};
+
+void false_positives() {
+#define OP =
+#define LHS a
+#define RHS a
+  int a = 42;
+  // These shouldn't warn due to the use of the preprocessor.
+  a OP a;
+  LHS = a;
+  a = RHS;
+  LHS OP RHS;
+#undef OP
+#undef LHS
+#undef RHS
+
+  // A way to silence the warning.
+  a = (int &)a;
+
+  // Volatile stores aren't side-effect free.
+  volatile int vol_a;
+  vol_a = vol_a;
+  volatile int &vol_a_ref = vol_a;
+  vol_a_ref = vol_a_ref;
+}
+
+// Do not diagnose self-assigment in an unevaluated context
+void false_positives_unevaluated_ctx(int a) noexcept(noexcept(a = a)) // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+{
+  decltype(a = a) b = a;              // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+  static_assert(noexcept(a = a), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+  static_assert(sizeof(a = a), "");   // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+}
+
+template <typename T>
+void g() {
+  T a;
+  a = a; // expected-warning{{explicitly assigning}}
+}
+void instantiate() {
+  g<int>();
+  g<S>();
+}

Added: cfe/trunk/test/SemaCXX/warn-self-assign-field-builtin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-self-assign-field-builtin.cpp?rev=329493&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-self-assign-field-builtin.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-self-assign-field-builtin.cpp Sat Apr  7 03:39:21 2018
@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -verify %s
+
+struct C {
+  int a;
+  int b;
+
+  void f() {
+    a = a; // expected-warning {{assigning field to itself}}
+    b = b; // expected-warning {{assigning field to itself}}
+    a = b;
+
+    this->a = a;       // expected-warning {{assigning field to itself}}
+    this->b = b;       // expected-warning {{assigning field to itself}}
+    a = this->a;       // expected-warning {{assigning field to itself}}
+    b = this->b;       // expected-warning {{assigning field to itself}}
+    this->a = this->a; // expected-warning {{assigning field to itself}}
+    this->b = this->b; // expected-warning {{assigning field to itself}}
+
+    a = b;
+    a = this->b;
+    this->a = b;
+    this->a = this->b;
+
+    a *= a;
+    a /= a;
+    a %= a;
+    a += a;
+    a -= a;
+    a <<= a;
+    a >>= a;
+    a &= a;
+    a |= a;
+    a ^= a;
+  }
+
+  void false_positives() {
+#define OP =
+#define LHS a
+#define RHS a
+    // These shouldn't warn due to the use of the preprocessor.
+    a OP a;
+    LHS = a;
+    a = RHS;
+    LHS OP RHS;
+#undef OP
+#undef LHS
+#undef RHS
+
+    // A way to silence the warning.
+    a = (int &)a;
+  }
+
+  // Do not diagnose self-assigment in an unevaluated context
+  void false_positives_unevaluated_ctx() noexcept(noexcept(a = a)) // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+  {
+    decltype(a = a) b = a;              // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+    static_assert(noexcept(a = a), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+    static_assert(sizeof(a = a), "");   // expected-warning {{expression with side effects has no effect in an unevaluated context}}
+  }
+
+  volatile int vol_a;
+  void vol_test() {
+    // Volatile stores aren't side-effect free.
+    vol_a = vol_a;
+    volatile int &vol_a_ref = vol_a;
+    vol_a_ref = vol_a_ref;
+  }
+};
+
+// Dummy type.
+struct Dummy {};
+
+template <typename T>
+struct TemplateClass {
+  T var;
+  void f() {
+    var = var; // expected-warning {{assigning field to itself}}
+  }
+};
+void instantiate() {
+  {
+    TemplateClass<int> c;
+    c.f();
+  }
+  {
+    TemplateClass<Dummy> c;
+    c.f();
+  }
+}
+
+// It may make sense not to warn on the rest of the tests.
+// It may be a valid use-case to self-assign to tell the compiler that
+// it is ok to vectorize the store.
+
+void f0(C *s, C *t) {
+  s->a = s->a;
+  t->a = s->a;
+}
+
+void f1(C &s, C &t) {
+  s.a = s.a;
+  t.a = s.a;
+}
+
+struct T {
+  C *s;
+};
+
+void f2(T *t, T *t2) {
+  t->s->a = t->s->a;
+  t2->s->a = t->s->a;
+}
+
+void f3(T &t, T &t2) {
+  t.s->a = t.s->a;
+  t2.s->a = t.s->a;
+}

Added: cfe/trunk/test/SemaCXX/warn-self-assign-field-overloaded.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-self-assign-field-overloaded.cpp?rev=329493&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-self-assign-field-overloaded.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-self-assign-field-overloaded.cpp Sat Apr  7 03:39:21 2018
@@ -0,0 +1,162 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DDUMMY -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV0 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV1 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV3 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign-field -DV4 -verify %s
+
+#ifdef DUMMY
+struct S {};
+#else
+struct S {
+#if defined(V0)
+  S() = default;
+#elif defined(V1)
+  S &operator=(const S &) = default;
+#elif defined(V2)
+  S &operator=(S &) = default;
+#elif defined(V3)
+  S &operator=(const S &);
+#elif defined(V4)
+  S &operator=(S &);
+#else
+#error Define something!
+#endif
+  S &operator*=(const S &);
+  S &operator/=(const S &);
+  S &operator%=(const S &);
+  S &operator+=(const S &);
+  S &operator-=(const S &);
+  S &operator<<=(const S &);
+  S &operator>>=(const S &);
+  S &operator&=(const S &);
+  S &operator|=(const S &);
+  S &operator^=(const S &);
+  S &operator=(const volatile S &) volatile;
+};
+#endif
+struct C {
+  S a;
+  S b;
+
+  void f() {
+    a = a; // expected-warning {{assigning field to itself}}
+    b = b; // expected-warning {{assigning field to itself}}
+    a = b;
+
+    this->a = a;       // expected-warning {{assigning field to itself}}
+    this->b = b;       // expected-warning {{assigning field to itself}}
+    a = this->a;       // expected-warning {{assigning field to itself}}
+    b = this->b;       // expected-warning {{assigning field to itself}}
+    this->a = this->a; // expected-warning {{assigning field to itself}}
+    this->b = this->b; // expected-warning {{assigning field to itself}}
+
+    a = b;
+    a = this->b;
+    this->a = b;
+    this->a = this->b;
+
+#ifndef DUMMY
+    a *= a;
+    a /= a; // expected-warning {{assigning field to itself}}
+    a %= a; // expected-warning {{assigning field to itself}}
+    a += a;
+    a -= a; // expected-warning {{assigning field to itself}}
+    a <<= a;
+    a >>= a;
+    a &= a; // expected-warning {{assigning field to itself}}
+    a |= a; // expected-warning {{assigning field to itself}}
+    a ^= a; // expected-warning {{assigning field to itself}}
+#endif
+  }
+
+  void false_positives() {
+#define OP =
+#define LHS a
+#define RHS a
+    // These shouldn't warn due to the use of the preprocessor.
+    a OP a;
+    LHS = a;
+    a = RHS;
+    LHS OP RHS;
+#undef OP
+#undef LHS
+#undef RHS
+
+    // Ways to silence the warning.
+    a = *&a;
+    a = (S &)a;
+    a = static_cast<decltype(a) &>(a);
+  }
+
+#ifndef DUMMY
+  volatile S vol_a;
+  void vol_test() {
+    // Volatile stores aren't side-effect free.
+    vol_a = vol_a;
+    volatile S &vol_a_ref = vol_a;
+    vol_a_ref = vol_a_ref;
+  }
+#endif
+};
+
+// Do not diagnose self-assigment in an unevaluated context
+struct SNoExcept {
+  SNoExcept() = default;
+  SNoExcept &operator=(const SNoExcept &) noexcept;
+};
+struct false_positives_unevaluated_ctx_class {
+  SNoExcept a;
+
+  void false_positives_unevaluated_ctx(SNoExcept a) noexcept(noexcept(a = a)) {
+    decltype(a = a) b = a;
+    static_assert(noexcept(a = a), "");
+    static_assert(sizeof(a = a), "");
+  }
+};
+
+template <typename T>
+struct TemplateClass {
+  T var;
+  void f() {
+    var = var; // expected-warning {{assigning field to itself}}
+  }
+};
+void instantiate() {
+  {
+    TemplateClass<int> c;
+    c.f();
+  }
+  {
+    TemplateClass<S> c;
+    c.f();
+  }
+}
+
+// It may make sense not to warn on the rest of the tests.
+// It may be a valid use-case to self-assign to tell the compiler that
+// it is ok to vectorize the store.
+
+void f0(C *s, C *t) {
+  s->a = s->a;
+  t->a = s->a;
+}
+
+void f1(C &s, C &t) {
+  s.a = s.a;
+  t.a = s.a;
+}
+
+struct T {
+  C *s;
+};
+
+void f2(T *t, T *t2) {
+  t->s->a = t->s->a;
+  t2->s->a = t->s->a;
+}
+
+void f3(T &t, T &t2) {
+  t.s->a = t.s->a;
+  t2.s->a = t.s->a;
+}

Added: cfe/trunk/test/SemaCXX/warn-self-assign-overloaded.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-self-assign-overloaded.cpp?rev=329493&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-self-assign-overloaded.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-self-assign-overloaded.cpp Sat Apr  7 03:39:21 2018
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DDUMMY -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV0 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV1 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV3 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wself-assign -DV4 -verify %s
+
+#ifdef DUMMY
+struct S {};
+#else
+struct S {
+#if defined(V0)
+  S() = default;
+#elif defined(V1)
+  S &operator=(const S &) = default;
+#elif defined(V2)
+  S &operator=(S &) = default;
+#elif defined(V3)
+  S &operator=(const S &);
+#elif defined(V4)
+  S &operator=(S &);
+#else
+#error Define something!
+#endif
+  S &operator*=(const S &);
+  S &operator/=(const S &);
+  S &operator%=(const S &);
+  S &operator+=(const S &);
+  S &operator-=(const S &);
+  S &operator<<=(const S &);
+  S &operator>>=(const S &);
+  S &operator&=(const S &);
+  S &operator|=(const S &);
+  S &operator^=(const S &);
+  S &operator=(const volatile S &) volatile;
+};
+#endif
+
+void f() {
+  S a, b;
+  a = a; // expected-warning{{explicitly assigning}}
+  b = b; // expected-warning{{explicitly assigning}}
+  a = b;
+  b = a = b;
+  a = a = a; // expected-warning{{explicitly assigning}}
+  a = b = b = a;
+
+#ifndef DUMMY
+  a *= a;
+  a /= a; // expected-warning {{explicitly assigning}}
+  a %= a; // expected-warning {{explicitly assigning}}
+  a += a;
+  a -= a; // expected-warning {{explicitly assigning}}
+  a <<= a;
+  a >>= a;
+  a &= a; // expected-warning {{explicitly assigning}}
+  a |= a; // expected-warning {{explicitly assigning}}
+  a ^= a; // expected-warning {{explicitly assigning}}
+#endif
+}
+
+void false_positives() {
+#define OP =
+#define LHS a
+#define RHS a
+  S a;
+  // These shouldn't warn due to the use of the preprocessor.
+  a OP a;
+  LHS = a;
+  a = RHS;
+  LHS OP RHS;
+#undef OP
+#undef LHS
+#undef RHS
+
+  // Ways to silence the warning.
+  a = *&a;
+  a = (S &)a;
+  a = static_cast<decltype(a) &>(a);
+
+#ifndef DUMMY
+  // Volatile stores aren't side-effect free.
+  volatile S vol_a;
+  vol_a = vol_a;
+  volatile S &vol_a_ref = vol_a;
+  vol_a_ref = vol_a_ref;
+#endif
+}
+
+// Do not diagnose self-assigment in an unevaluated context
+struct SNoExcept {
+  SNoExcept() = default;
+  SNoExcept &operator=(const SNoExcept &) noexcept;
+};
+void false_positives_unevaluated_ctx(SNoExcept a) noexcept(noexcept(a = a)) {
+  decltype(a = a) b = a;
+  static_assert(noexcept(a = a), "");
+  static_assert(sizeof(a = a), "");
+}
+
+template <typename T>
+void g() {
+  T a;
+  a = a; // expected-warning{{explicitly assigning}}
+}
+void instantiate() {
+  g<int>();
+  g<S>();
+}

Removed: cfe/trunk/test/SemaCXX/warn-self-assign.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-self-assign.cpp?rev=329492&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-self-assign.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-self-assign.cpp (removed)
@@ -1,50 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -Wself-assign -verify %s
-
-void f() {
-  int a = 42, b = 42;
-  a = a; // expected-warning{{explicitly assigning}}
-  b = b; // expected-warning{{explicitly assigning}}
-  a = b;
-  b = a = b;
-  a = a = a; // expected-warning{{explicitly assigning}}
-  a = b = b = a;
-  a &= a; // expected-warning{{explicitly assigning}}
-  a |= a; // expected-warning{{explicitly assigning}}
-  a ^= a;
-}
-
-// Dummy type.
-struct S {};
-
-void false_positives() {
-#define OP =
-#define LHS a
-#define RHS a
-  int a = 42;
-  // These shouldn't warn due to the use of the preprocessor.
-  a OP a;
-  LHS = a;
-  a = RHS;
-  LHS OP RHS;
-#undef OP
-#undef LHS
-#undef RHS
-
-  S s;
-  s = s; // Not a builtin assignment operator, no warning.
-
-  // Volatile stores aren't side-effect free.
-  volatile int vol_a;
-  vol_a = vol_a;
-  volatile int &vol_a_ref = vol_a;
-  vol_a_ref = vol_a_ref;
-}
-
-template <typename T> void g() {
-  T a;
-  a = a; // May or may not be a builtin assignment operator, no warning.
-}
-void instantiate() {
-  g<int>();
-  g<S>();
-}




More information about the cfe-commits mailing list