[PATCH] D16770: [MS] PR26234: Allow typedef redefinition of equally qualified, sized and aligned types in C

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 3 09:49:48 PST 2016


rnk added inline comments.

================
Comment at: include/clang/AST/ASTContext.h:1772-1783
@@ -1771,1 +1771,14 @@
 
+  /// Return true is the given typedef types are compatible in C from MSVC's
+  /// point of view.
+  //
+  // Conditions:
+  //   1. Both typedef types are either integer, enumeral or pointers;
+  //   2. Both typedef types have the same qualifiers and signedness;
+  //   3. Both typedef types have the same size and alignment;
+  //   4. If pointers:
+  //     4.1. Levels of pointers are equal;
+  //     4.2. Pointee types are MSVC-compatible OR
+  //     4.3. One type points to void and another points to char.
+  bool areMSCompatibleTypedefTypesInC(QualType OldType, QualType NewType);
+
----------------
d.zobnin.bugzilla wrote:
> By the way, MSVC allows to redefine not anly typedefs, but variables as well (under the same conditions as typedefs):
> 
> ```
> int x;
> long x;
> ```
> Typedef redefinition seems to be just an example of MSVC's permissive behavior. The same for return types, etc.
> 
> So, do you think we need to compatible with MSVC, for example, also considering only integer types?
> So, do you think we need to compatible with MSVC, for example, also considering only integer types?

I'd rather not for now. I can imagine that there's lots of code out there with crazy mixed up typedefs that it's useful to accept, but it's a lot less common to re-prototype someone else's functions incorrectly.

================
Comment at: lib/Sema/SemaDecl.cpp:1898-1902
@@ +1897,7 @@
+          << NewType << OldType;
+      if (OldTypedef->isModed())
+        New->setModedTypeSourceInfo(OldTypedef->getTypeSourceInfo(),
+                                    OldTypedef->getUnderlyingType());
+      else
+        New->setTypeSourceInfo(OldTypedef->getTypeSourceInfo());
+      OldLocation = OldTypedef->getFirstDecl()->getLocation();
----------------
Hm, this seems like an AST fidelity issue that Richard would care about. The TSI should reflect the type the user wrote at this position. Maybe you could wrap an AdjustedType node around the original type and install that instead.


http://reviews.llvm.org/D16770





More information about the cfe-commits mailing list