12

I am using Xcode 7.3, and I am getting an "Ambiguous expansion of macro" warning, for a macro which was defined in Foundation, but which I have undefined and re-defined in my prefix file. I have modules enabled.

To reproduce:

  • Set "Enable Modules (C and Objective-C)" to Yes in build settings
  • Use the following prefix file:

    #import <Foundation/Foundation.h>  
    
    #undef assert  
    #define assert(e)  NSLog(@"hi") // implementation is not important  
    
  • Use the following main source file:

    int main() {  
      assert(42);  
      return 0;  
    }  
    
  • Then build in Xcode.

  • It shows an "Ambiguous expansion of macro 'assert'" warning on the line in the source file that uses the "assert" macro. The "Expanding this definition of 'assert'" points to the definition from the system header, not my redefinition. The "Other definition of 'assert'" points to the definition in my prefix file.

This warning does not happen when modules is disabled.

user102008
  • 30,736
  • 10
  • 83
  • 104
  • Does this answer your question? [Xcode 8 Ambiguous expansion of macro NSLocalizedString](https://stackoverflow.com/questions/39635624/xcode-8-ambiguous-expansion-of-macro-nslocalizedstring) – Eugene Berdnikov Feb 22 '20 at 20:29

1 Answers1

6

This is a bug in Xcode; we'd appreciate if you could file a bug report at https://bugreport.apple.com and leave the bug # in a comment here. Your options for working around this bug in the meantime are:

  • You could use a different name than "assert" for this macro.
  • You could set the GCC_PRECOMPILE_PREFIX_HEADER build setting to NO, since PCH don’t provide a lot of benefit when you already have modules. The prefix header will still work, it just won’t be turned into a PCH.
  • You could turn off modules.
Rick Ballard
  • 4,765
  • 2
  • 19
  • 17