#1325 Macros _ and __ defined in Ruby defines.h conflict with libc++ standard library headers

open
nobody
None
5
2014-08-17
2013-05-14
No

I'm trying to compile a Ruby extension module with SWIG 2.0.9 on OS X 10.8 using Clang/libc++, and I'm getting the following error:

/usr/bin/../lib/c++/v1/type_traits:1926:25: error: declaration of '_Tp' shadows template parameter
    true_type static __(_Tp);
                    ^
/System/Library/Frameworks/Ruby.framework/Headers/defines.h:33:19: note: expanded from macro '__'
# define __(args) args
              ^
/usr/bin/../lib/c++/v1/type_traits:1923:17: note: template parameter is declared here
template <class _Tp>

Seems to me like '_' and '__' should be undefined in the SWIG-generated source file (e.g. example_rubyRUBY_wrap.cxx) just like the write, read, bind, close, and connect macros defined in Ruby's win32.h.

Discussion

  • William Fulton

    William Fulton - 2013-05-14

    Can you find out what this is meant to be doing as just undefining it may break a whole pile of things. Defining __ is illegal in the standard, as double underscores are reserved for the implementation, so the Ruby developers shouldn't be putting this in their headers.

    Is it clang only or OSX only? Either way I'd like to know what the Ruby developers fix is.

     
  • Ian Mackenzie

    Ian Mackenzie - 2013-05-14

    From http://www.ruby-forum.com/topic/52410: "These are provided so ruby can compile on old (pre-ANSI) compilers that lack function prototypes". Your point about __ being illegal occurred to me too, although is that true in C or just C++? I wondered if we might be in a situation where the Ruby headers are legal C but illegal C++.

    I've only tried it on OSX/Clang so far - I can try it out on Linux/GCC and Windows/MSVC soon (hopefully within a day or so once I get this code committed and pushed to my central repository). I just figured that it was probably a quirk of libc++ (i.e., other standard library implementations had more #ifdef/#undef guards for this sort of thing or something like that). Shall I file a Ruby bug as well?

     
  • Ian Mackenzie

    Ian Mackenzie - 2013-05-14

    Hmm, double underscore definitely seems to be illegal in C (http://stackoverflow.com/questions/1449181/what-does-double-underscore-const-mean-in-c) - looks like I should file a Ruby bug. By the way, I did try to add

    %{
        #undef _
        #undef __
    %}
    

    to my interface file to see what would happen, but those got inserted into the generated wrapper file just below the #include <stdexcept> line that triggered the error.

     
  • William Fulton

    William Fulton - 2013-05-14

    Legal double underscores are illegal in C and C++.

    We test Ruby 1.9 using Linux/gcc, so I doubt that setup will be problematic, although the 1.9 support is only really fully working in the upcoming swig-2.0.10.

    It looks like it is an oversight/problem in the Ruby headers to me.

    You can use

    ~~~~~
    %begin %{
    #undef _
    #undef __
    %}

    to put this at the very top of the interface file.

     
    Last edit: William Fulton 2013-05-14

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks