+2014-01-16 Jason Merrill <jason@redhat.com>
+
+ PR c++/59821
+ * tree.c (bot_manip): Update the location of builtin_LINE and
+ builtin_FILE calls.
+
2014-01-14 Jason Merrill <jason@redhat.com>
PR c++/59659
/* Make a copy of this node. */
t = copy_tree_r (tp, walk_subtrees, NULL);
if (TREE_CODE (*tp) == CALL_EXPR)
- set_flags_from_callee (*tp);
+ {
+ set_flags_from_callee (*tp);
+
+ /* builtin_LINE and builtin_FILE get the location where the default
+ argument is expanded, not where the call was written. */
+ tree callee = get_callee_fndecl (*tp);
+ if (callee && DECL_BUILT_IN (callee))
+ switch (DECL_FUNCTION_CODE (callee))
+ {
+ case BUILT_IN_FILE:
+ case BUILT_IN_LINE:
+ SET_EXPR_LOCATION (*tp, input_location);
+ }
+ }
return t;
}
@deftypefn {Built-in Function} int __builtin_LINE ()
This function is the equivalent to the preprocessor @code{__LINE__}
macro and returns the line number of the invocation of the built-in.
+In a C++ default argument for a function @var{F}, it gets the line number of
+the call to @var{F}.
@end deftypefn
@deftypefn {Built-in Function} {const char *} __builtin_FUNCTION ()
@deftypefn {Built-in Function} {const char *} __builtin_FILE ()
This function is the equivalent to the preprocessor @code{__FILE__}
macro and returns the file name the invocation of the built-in is in.
+In a C++ default argument for a function @var{F}, it gets the file name of
+the call to @var{F}.
@end deftypefn
@deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end})
--- /dev/null
+// __builtin_LINE gets the location where the default argument is expanded.
+// { dg-do run }
+
+#include <cassert>
+struct Foo
+{
+ int line;
+ Foo( int line = __builtin_LINE() )
+ : line( line )
+ {}
+};
+
+int main()
+{
+ assert (Foo().line == __LINE__);
+ assert ((new Foo)->line == __LINE__);
+}