Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7.3: "Ambiguous expansion of macro" when re-defining macro in prefix file

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.

like image 987
user102008 Avatar asked Mar 21 '16 23:03

user102008


1 Answers

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.
like image 109
Rick Ballard Avatar answered Oct 23 '22 18:10

Rick Ballard