Bug 70819 - constexpr error location wrong
Summary: constexpr error location wrong
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2016-04-27 13:40 UTC by Nathan Sidwell
Modified: 2023-12-04 19:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase (124 bytes, text/plain)
2016-04-27 13:40 UTC, Nathan Sidwell
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Sidwell 2016-04-27 13:40:26 UTC
Created attachment 38345 [details]
testcase

Invoked as:
nathan@morden:28>./cc1plus -fpreprocessed cexpr-error.ii 

we get:

 constexpr int fn6(const int&, int) constexpr int fn7(const int*, int)
cexpr-error.ii: At global scope:
cexpr-error.ii:17:24:   in constexpr expansion of 'fn7(0u, 0)'
cexpr-error.ii:14:14:   in constexpr expansion of 'fn6((* a), b)'
cexpr-error.ii:7:7: error: 'a' is not a constant expression
   b = a;
       ^
cexpr-error.ii:18:24:   in constexpr expansion of 'fn7(0u, 8)'
cexpr-error.ii:14:14:   in constexpr expansion of 'fn6((* a), b)'
cexpr-error.ii:6:13:   in constexpr expansion of 'fn6(a, 0)'
cexpr-error.ii:18:43: error: 'a' is not a constant expression
 constexpr int n4 = fn7 ((const int *) 0, 8);

The first error is correctly located at tha 'b = a;' location.  The second instance is  not, and shows the original call site.  inside constexpr.c the first error is from an evaluation of the original function body.  the second is from a cloned copy via the recursive call.  Something about cloning is throwing off the error location.
Comment 1 Drea Pinski 2023-12-02 03:33:08 UTC
GCC 7-13 does:
```
<source>:17:24:   in constexpr expansion of 'fn7(0, 0)'
<source>:17:43: error: dereferencing a null pointer
 constexpr int n3 = fn7 ((const int *) 0, 0);
                                           ^
<source>:18:24:   in constexpr expansion of 'fn7(0, 8)'
<source>:18:43: error: dereferencing a null pointer
 constexpr int n4 = fn7 ((const int *) 0, 8);
                                           ^
```

While the trunk gives:
```
<source>:17:24:   in 'constexpr' expansion of 'fn7(0, 0)'
<source>:14:14: error: dereferencing a null pointer
   14 |   return fn6 (*a, b);
      |          ~~~~^~~~~~~
<source>:18:24:   in 'constexpr' expansion of 'fn7(0, 8)'
<source>:14:14: error: dereferencing a null pointer
```

Which seems like the correct location now.
Comment 2 Marek Polacek 2023-12-04 19:23:19 UTC
Changed in r14-2771

commit 5ebe5bcf8b6b6a0de16737b717e8bd06e4950a14
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Sun Jul 23 01:13:43 2023 +1000

    c++: Improve location information in constant evaluation

So I guess fixed.