]> granicus.if.org Git - clang/commitdiff
Always allow redefinition of typedefs when modules are enabled. This
authorDouglas Gregor <dgregor@apple.com>
Mon, 9 Jan 2012 15:36:04 +0000 (15:36 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 9 Jan 2012 15:36:04 +0000 (15:36 +0000)
is important because it's fairly common for headers (especially system
headers) to want to provide only those typedefs needed for that
particular header, based on some guard macro, e.g.,

#ifndef _SIZE_T
#define _SIZE_T
typedef long size_t;
#endif

which is repeated in a number of headers. The guard macro protects
against duplicate definitions. However, this means that only the first
occurrence of this pattern actually defines size_t, so the submodule
corresponding to this header has the only visible definition. If a
user then imports a different submodule from the same module, size_t
will be known but not visible, and therefore cannot be used.

By allowing redefinition of typedefs, each header that wants to define
size_t can do so independently, so it will be available in the
corresponding submodules.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147775 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Modules/redecl-merge.m

index 54f953d343712f1c45b919e2924a57cddfb7f47e..b541e7d9e717a47b3763aa5e8757e8958b796470 100644 (file)
@@ -1509,6 +1509,10 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) {
     return New->setInvalidDecl();
   }
 
+  // Modules always permit redefinition of typedefs.
+  if (getLangOptions().Modules)
+    return;
+  
   // If we have a redefinition of a typedef in C, emit a warning.  This warning
   // is normally mapped to an error, but can be controlled with
   // -Wtypedef-redefinition.  If either the original or the redefinition is
index 09898a5b3b8a6728d582660b390eb1195ab491c5..e6de22a85aa06ebc709de13acdc4d9dd6355a813 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fmodule-cache-path %t -Wno-typedef-redefinition -I %S/Inputs %s -verify
+// RUN: %clang_cc1 -fmodules -fmodule-cache-path %t -I %S/Inputs %s -verify
 // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodule-cache-path %t -I %S/Inputs %s -verify
 @class C2;
 @class C3;