================
@@ -9966,8 +9966,13 @@ AssignConvertType 
Sema::CheckSingleAssignmentConstraints(QualType LHSType,
       // If there is a conversion of some kind, check to see what kind of
       // pointer conversion happened so we can diagnose a C++ compatibility
       // diagnostic if the conversion is invalid. This only matters if the RHS
-      // is some kind of void pointer.
-      if (Kind != CK_NoOp && !getLangOpts().CPlusPlus) {
+      // is some kind of void pointer. We have a carve-out when the RHS is from
+      // a macro expansion because the use of a macro may indicate different
+      // code between C and C++. Consider: char *s = NULL; where NULL is
+      // defined as (void *)0 in C (which would be invalid in C++), but 0 in
+      // C++, which is valid in C++.
+      if (Kind != CK_NoOp && !getLangOpts().CPlusPlus &&
+          !RHS.get()->getBeginLoc().isMacroID()) {
----------------
AaronBallman wrote:

Ah, nope! We've got a test for that:
```
 #define SOMETHING_THAT_IS_NOT_NULL (void *)12

  char *ptr3 = SOMETHING_THAT_IS_NOT_NULL; // c-warning {{implicit conversion 
when initializing 'char *' with an expression of type 'void *' is not permitted 
in C++}} \
                                              cxx-error {{cannot initialize a 
variable of type 'char *' with an rvalue of type 'void *'}}

  ...

  ptr3 = SOMETHING_THAT_IS_NOT_NULL; // c-warning {{implicit conversion when 
assigning to 'char *' from type 'void *' is not permitted in C++}} \
                                        cxx-error {{assigning to 'char *' from 
incompatible type 'void *'}}
```

https://github.com/llvm/llvm-project/pull/140724
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to