summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2014-01-16 19:55:12 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2014-01-16 19:55:12 +0000
commit5b5af642816ed0feb44d646299ed37bb557b2a54 (patch)
tree512300df630ee084b93066981e5a3d43ef3d5010
parente8e60ada8c4537a0316142e7f701ad2615526e36 (diff)
downloadlinaro-gcc-5b5af642816ed0feb44d646299ed37bb557b2a54.tar.gz
linaro-gcc-5b5af642816ed0feb44d646299ed37bb557b2a54.tar.bz2
linaro-gcc-5b5af642816ed0feb44d646299ed37bb557b2a54.zip
PR c++/59821
* tree.c (bot_manip): Update the location of builtin_LINE and builtin_FILE calls. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206686 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/tree.c15
-rw-r--r--gcc/doc/extend.texi4
-rw-r--r--gcc/testsuite/g++.dg/ext/builtin-line1.C17
4 files changed, 41 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c15c8fd511c..848c406ecf4 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 7aad1eb9bd4..ce41c3b1930 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2306,7 +2306,20 @@ bot_manip (tree* tp, int* walk_subtrees, void* data)
/* 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;
}
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 84fd594b605..2f4f91d233a 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -8726,6 +8726,8 @@ means that the compiler can assume for @code{x}, set to @code{arg}, that
@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 ()
@@ -8736,6 +8738,8 @@ macro and returns the function name the invocation of the built-in is in.
@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})
diff --git a/gcc/testsuite/g++.dg/ext/builtin-line1.C b/gcc/testsuite/g++.dg/ext/builtin-line1.C
new file mode 100644
index 00000000000..21a4f59a46f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/builtin-line1.C
@@ -0,0 +1,17 @@
+// __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__);
+}