Re: Add the latest C++ SD-6 additions.
On 2014.11.11 at 19:15 +0100, Markus Trippelsdorf wrote: On 2014.11.10 at 10:55 -0500, Ed Smith-Rowland wrote: On 11/09/2014 11:45 PM, Jason Merrill wrote: On 11/09/2014 08:33 PM, Ed Smith-Rowland wrote: + //cpp_hashnode *node = 0; + //node = token-val.node.node; + //if (node) + // pfile-mi_ind_cmacro = node; Remove this commented-out code? The patch is OK. Jason Here is the committed patch. It has those comments removed and has some test case cleanup. This patch causes numerous segfaults when building Firefox, e.g.: trippels@gcc1-power7 gecko-dev % /home/trippels/gcc_test/usr/local/bin/g++ -I /home/trippels/gecko-dev/intl/icu/source/common -MM test.cpp built-in: internal compiler error: Segmentation fault 0x109b64ab crash_signal ../../gcc/gcc/toplev.c:358 0x110b3d30 parse_has_attribute ../../gcc/libcpp/expr.c:2165 0x110b3d30 eval_token ../../gcc/libcpp/expr.c:1059 0x110b3d30 _cpp_parse_expr ../../gcc/libcpp/expr.c:1227 Please submit a full bug report, I've opened https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63831 with a testcase. -- Markus
Re: Add the latest C++ SD-6 additions.
On 11/11/2014 12:52 AM, Ed Smith-Rowland wrote: I'll might put this to the SD-6 list because it would be nice to have clarity - even if it's implementation defined. Sounds good. I was thinking that defining to 0 tells the user this isn't supported which seems more useful than this may or may not be supported. Jason
Re: Add the latest C++ SD-6 additions.
On 2014.11.10 at 10:55 -0500, Ed Smith-Rowland wrote: On 11/09/2014 11:45 PM, Jason Merrill wrote: On 11/09/2014 08:33 PM, Ed Smith-Rowland wrote: + //cpp_hashnode *node = 0; + //node = token-val.node.node; + //if (node) + // pfile-mi_ind_cmacro = node; Remove this commented-out code? The patch is OK. Jason Here is the committed patch. It has those comments removed and has some test case cleanup. This patch causes numerous segfaults when building Firefox, e.g.: (4.9 is fine:) trippels@gcc1-power7 gecko-dev % g++ -I /home/trippels/gecko-dev/intl/icu/source/common -MM test.cpp test.o: test.cpp \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/utf_old.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/utf.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/umachine.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/ptypes.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/platform.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/uconfig.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/uvernum.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/urename.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/utf8.h \ /home/trippels/gecko-dev/intl/icu/source/common/unicode/utf16.h (trunk crashes:) trippels@gcc1-power7 gecko-dev % /home/trippels/gcc_test/usr/local/bin/g++ -I /home/trippels/gecko-dev/intl/icu/source/common -MM test.cpp built-in: internal compiler error: Segmentation fault 0x109b64ab crash_signal ../../gcc/gcc/toplev.c:358 0x110b3d30 parse_has_attribute ../../gcc/libcpp/expr.c:2165 0x110b3d30 eval_token ../../gcc/libcpp/expr.c:1059 0x110b3d30 _cpp_parse_expr ../../gcc/libcpp/expr.c:1227 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See http://gcc.gnu.org/bugs.html for instructions. -- Markus
Re: Add the latest C++ SD-6 additions.
On 11/10/2014 12:10 PM, Jason Merrill wrote: On 11/10/2014 10:55 AM, Ed Smith-Rowland wrote: Would a 4.9 version be accepted? Sure. What do you think about defining the macros for unsupported features to 0 rather than leaving them undefined? The document doesn't seem to specify. Jason Jason, 1. Undefined macros evaluate to 0 so that's effectively what we have now - no change in behavior if we explicitly set them 2. The SD-6 document advertises direct use of macros with #if __cpp_foobar without #ifdef - However if people are using #ifdef rather than #if that might break things (I guess that's different behavior); OTOH those dates are there for a reason. 3. OTOH, the SD-6 document seems to suggest only adding a macro as a feature is implemented or allowed bycompiler flags - implying undefined macros for unimplemented features 4. __has_include and __has_cpp_attribute return 0 on non-existent/undefined so there's some precedent (though these are rather different structurally - function macros) So I'm conflicted after being initially sympathetic to defining as zero. Still slightly in favor. I'll might put this to the SD-6 list because it would be nice to have clarity - even if it's implementation defined. Ed
Re: Add the latest C++ SD-6 additions.
On 11/09/2014 11:45 PM, Jason Merrill wrote: On 11/09/2014 08:33 PM, Ed Smith-Rowland wrote: + //cpp_hashnode *node = 0; + //node = token-val.node.node; + //if (node) + // pfile-mi_ind_cmacro = node; Remove this commented-out code? The patch is OK. Jason Here is the committed patch. It has those comments removed and has some test case cleanup. Would a 4.9 version be accepted? Thanks, Ed Index: libcpp/include/cpplib.h === --- libcpp/include/cpplib.h (revision 217269) +++ libcpp/include/cpplib.h (working copy) @@ -580,6 +580,9 @@ Second argument is the location of the start of the current expansion. */ void (*used) (cpp_reader *, source_location, cpp_hashnode *); + /* Callback to identify whether an attribute exists. */ + int (*has_attribute) (cpp_reader *); + /* Callback that can change a user builtin into normal macro. */ bool (*user_builtin_macro) (cpp_reader *, cpp_hashnode *); }; Index: libcpp/internal.h === --- libcpp/internal.h (revision 217269) +++ libcpp/internal.h (working copy) @@ -261,6 +261,9 @@ /* Nonzero if in a __has_include__ or __has_include_next__ statement. */ unsigned char in__has_include__; + /* Nonzero if in a __has_attribute__ statement. */ + unsigned char in__has_attribute__; + /* Nonzero if prevent_expansion is true only because output is being discarded. */ unsigned char discarding_output; @@ -284,6 +287,7 @@ cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ cpp_hashnode *n__has_include__; /* __has_include__ operator */ cpp_hashnode *n__has_include_next__; /* __has_include_next__ operator */ + cpp_hashnode *n__has_attribute__;/* __has_attribute__ operator */ }; typedef struct _cpp_line_note _cpp_line_note; Index: libcpp/directives.c === --- libcpp/directives.c (revision 217269) +++ libcpp/directives.c (working copy) @@ -571,6 +571,10 @@ || node == pfile-spec_nodes.n__has_include_next__)) cpp_error (pfile, CPP_DL_ERROR, \__has_include__\ cannot be used as a macro name); + else if (is_def_or_undef +node == pfile-spec_nodes.n__has_attribute__) + cpp_error (pfile, CPP_DL_ERROR, + \__has_attribute__\ cannot be used as a macro name); else if (! (node-flags NODE_POISONED)) return node; } Index: libcpp/expr.c === --- libcpp/expr.c (revision 217269) +++ libcpp/expr.c (working copy) @@ -65,6 +65,7 @@ static void check_promotion (cpp_reader *, const struct op *); static cpp_num parse_has_include (cpp_reader *, enum include_type); +static cpp_num parse_has_attribute (cpp_reader *); /* Token type abuse to create unary plus and minus operators. */ #define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1)) @@ -1054,6 +1055,8 @@ return parse_has_include (pfile, IT_INCLUDE); else if (token-val.node.node == pfile-spec_nodes.n__has_include_next__) return parse_has_include (pfile, IT_INCLUDE_NEXT); + else if (token-val.node.node == pfile-spec_nodes.n__has_attribute__) + return parse_has_attribute (pfile); else if (CPP_OPTION (pfile, cplusplus) (token-val.node.node == pfile-spec_nodes.n_true || token-val.node.node == pfile-spec_nodes.n_false)) @@ -2147,3 +2150,21 @@ return result; } + +/* Handle meeting __has_attribute__ in a preprocessor expression. */ +static cpp_num +parse_has_attribute (cpp_reader *pfile) +{ + pfile-state.in__has_attribute__++; + + cpp_num result; + result.unsignedp = false; + result.high = 0; + result.overflow = false; + + result.low = pfile-cb.has_attribute (pfile); + + pfile-state.in__has_attribute__--; + + return result; +} Index: libcpp/identifiers.c === --- libcpp/identifiers.c(revision 217269) +++ libcpp/identifiers.c(working copy) @@ -72,6 +72,7 @@ s-n__VA_ARGS__-flags |= NODE_DIAGNOSTIC; s-n__has_include__ = cpp_lookup (pfile, DSC(__has_include__)); s-n__has_include_next__ = cpp_lookup (pfile, DSC(__has_include_next__)); + s-n__has_attribute__ = cpp_lookup (pfile, DSC(__has_attribute__)); } /* Tear down the identifier hash table. */ Index: libcpp/pch.c === --- libcpp/pch.c(revision 217269) +++ libcpp/pch.c(working copy) @@ -835,6 +835,7 @@ s-n__VA_ARGS__ = cpp_lookup (r, DSC(__VA_ARGS__)); s-n__has_include__ = cpp_lookup (r, DSC(__has_include__)); s-n__has_include_next__ = cpp_lookup (r, DSC(__has_include_next__)); +s-n__has_attribute__ = cpp_lookup (r, DSC(__has_attribute__)); } old_state
Re: Add the latest C++ SD-6 additions.
On 11/10/2014 10:55 AM, Ed Smith-Rowland wrote: Would a 4.9 version be accepted? Sure. What do you think about defining the macros for unsupported features to 0 rather than leaving them undefined? The document doesn't seem to specify. Jason
Add the latest C++ SD-6 additions.
I would like to put this patch out before Stage 1 ends even if there is bikeshed renaming of macros in the next couple weeks as the C++ committee wraps up after their meeting. The main part of this patch is a __has_cpp_attribute macro. #if __has_cpp_attribute(foobar) #else #endif In C++ we can use namespaces as well: #if __has_cpp_attribute(gnu::foobar) #else #endif I also added __has_attribute with the same sematics as an extension since clang has it. I made these available to C as well as C++. There are also two C++98 flags in SD-6 added since most compilers allow one to switch these features off: __cpp_rtti, __cpp_exceptions. These are not defined if -fno-rtti -fno-exceptions respectively. Also, the macro __cpp_attribute_deprecated has been removed in favor of __has_cpp_attribute(deprecated). Since __cpp_attribute_deprecated is out in the wild in the latest gcc-4.9 release perhaps I need to support this even if, in an ironic twist, __cpp_attribute_deprecated is deprecated. Let me know. This builds clean on x86_64-linux. Is this OK once it passes testing? Ed libcpp: 2014-11-10 Edward Smith-Rowland 3dw...@verizon.net * include/cpplib.h (cpp_callbacks): Add has_attribute. * internal.h (lexer_state): Add in__has_attribute__. * directives.c (lex_macro_node): Prevent use of __has_attribute__ as a macro. * expr.c (parse_has_attribute): New function; (eval_token): Look for __has_attribute__ and route to parse_has_attribute. * identifiers.c (_cpp_init_hashtable): Initialize n__has_attribute__. * pch.c (cpp_read_state): Initialize n__has_attribute__. * traditional.c (enum ls): Add ls_has_attribute, ls_has_attribute_close; (_cpp_scan_out_logical_line): Attend to __has_attribute__. gcc/c-family: 2014-11-10 Edward Smith-Rowland 3dw...@verizon.net * c-cppbuiltin.c (__has_attribute, __has_cpp_attribute): New macros; (__cpp_rtti, __cpp_exceptions): New macros for C++98; (__cpp_range_based_for, __cpp_initializer_lists, __cpp_delegating_constructors, __cpp_nsdmi, __cpp_inheriting_constructors, __cpp_ref_qualifiers): New macros for C++11; (__cpp_attribute_deprecated): Remove in favor of __has_cpp_attribute. * c-lex.c (cb_has_attribute): New callback CPP function; (init_c_lex): Set has_attribute callback. gcc/testsuite: 2014-11-10 Edward Smith-Rowland 3dw...@verizon.net * g++.dg/cpp1y/feat-cxx11.C: Test new feature macros for C++98 and C++11; Test existence of __has_cpp_attribute; Test C++11 attributes. * g++.dg/cpp1y/feat-cxx11-neg.C: Ditto. * g++.dg/cpp1y/feat-cxx14.C: Ditto and test for C++14 attributes. * g++.dg/cpp1y/feat-cxx98.C: Test new feature macros for C++98. * g++.dg/cpp1y/feat-cxx98-neg.C: Ditto. * g++.dg/cpp1y/feat-neg.C: Test that __cpp_rtti, _cpp_exceptions will be undefined for -fno-rtti -fno-exceptions. Index: libcpp/include/cpplib.h === --- libcpp/include/cpplib.h (revision 217269) +++ libcpp/include/cpplib.h (working copy) @@ -580,6 +580,9 @@ Second argument is the location of the start of the current expansion. */ void (*used) (cpp_reader *, source_location, cpp_hashnode *); + /* Callback to identify whether an attribute exists. */ + int (*has_attribute) (cpp_reader *); + /* Callback that can change a user builtin into normal macro. */ bool (*user_builtin_macro) (cpp_reader *, cpp_hashnode *); }; Index: libcpp/internal.h === --- libcpp/internal.h (revision 217269) +++ libcpp/internal.h (working copy) @@ -261,6 +261,9 @@ /* Nonzero if in a __has_include__ or __has_include_next__ statement. */ unsigned char in__has_include__; + /* Nonzero if in a __has_attribute__ statement. */ + unsigned char in__has_attribute__; + /* Nonzero if prevent_expansion is true only because output is being discarded. */ unsigned char discarding_output; @@ -284,6 +287,7 @@ cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ cpp_hashnode *n__has_include__; /* __has_include__ operator */ cpp_hashnode *n__has_include_next__; /* __has_include_next__ operator */ + cpp_hashnode *n__has_attribute__;/* __has_attribute__ operator */ }; typedef struct _cpp_line_note _cpp_line_note; Index: libcpp/directives.c === --- libcpp/directives.c (revision 217269) +++ libcpp/directives.c (working copy) @@ -571,6 +571,10 @@ || node == pfile-spec_nodes.n__has_include_next__)) cpp_error (pfile, CPP_DL_ERROR, \__has_include__\ cannot be used as a macro name); + else if (is_def_or_undef +node == pfile-spec_nodes.n__has_attribute__) + cpp_error (pfile,
Re: Add the latest C++ SD-6 additions.
On 11/09/2014 08:33 PM, Ed Smith-Rowland wrote: + //cpp_hashnode *node = 0; + //node = token-val.node.node; + //if (node) + // pfile-mi_ind_cmacro = node; Remove this commented-out code? The patch is OK. Jason