On Tue, 2024-11-12 at 09:02 -0500, David Malcolm wrote:
> This patch uses the nested diagnostics capabilities added in the
> earlier
> patch in the C++ frontend.
>
> With this, and enabling the non-standard text formatting via:
> -fdiagnostics-set-output=text:experimental-nesting=yes
> and using:
> -std=c++20 -fconcepts-diagnostics-depth=2
> then the output for the example in SG15's P3358R0 ("SARIF for
> Structured
> Diagnostics") is:
>
> P3358R0.C: In function ‘int main()’:
> P3358R0.C:26:6: error: no matching function for call to ‘pet(lizard)’
> 26 | pet(lizard{});
> | ~~~^~~~~~~~~~
> • note: candidate: ‘template<class auto:1> requires
> pettable<auto:1> void pet(auto:1)’
> P3358R0.C:21:6:
> 21 | void pet(pettable auto t);
> | ^~~
> • note: template argument deduction/substitution failed:
> • note: constraints not satisfied
> • P3358R0.C: In substitution of ‘template<class auto:1>
> requires pettable<auto:1> void pet(auto:1) [with auto:1 = lizard]’:
> • required from here
> P3358R0.C:26:6:
> 26 | pet(lizard{});
> | ~~~^~~~~~~~~~
> • required for the satisfaction of ‘pettable<auto:1>’ [with
> auto:1 = lizard]
> P3358R0.C:19:9:
> 19 | concept pettable = has_member_pet<T> or
> has_default_pet<T>;
> | ^~~~~~~~
> • note: no operand of the disjunction is satisfied
> P3358R0.C:19:38:
> 19 | concept pettable = has_member_pet<T> or
> has_default_pet<T>;
> |
> ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
> • note: the operand ‘has_member_pet<T>’ is unsatisfied
> because
> P3358R0.C:19:20:
> 19 | concept pettable = has_member_pet<T> or
> has_default_pet<T>;
> |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> • required for the satisfaction of ‘has_member_pet<T>’
> [with T = lizard]
> P3358R0.C:13:9:
> 13 | concept has_member_pet = requires(T t) {
> t.pet(); };
> | ^~~~~~~~~~~~~~
> • required for the satisfaction of ‘pettable<auto:1>’
> [with auto:1 = lizard]
> P3358R0.C:19:9:
> 19 | concept pettable = has_member_pet<T> or
> has_default_pet<T>;
> | ^~~~~~~~
> • in requirements with ‘T t’ [with T = lizard]
> P3358R0.C:13:26:
> 13 | concept has_member_pet = requires(T t) {
> t.pet(); };
> |
> ^~~~~~~~~~~~~~~~~~~~~~~~~~
> • note: the required expression ‘t.pet()’ is invalid,
> because
> P3358R0.C:13:47:
> 13 | concept has_member_pet = requires(T t) {
> t.pet(); };
> |
> ~~~~~^~
> • error: ‘struct lizard’ has no member named ‘pet’
> P3358R0.C:13:44:
> 13 | concept has_member_pet = requires(T t) {
> t.pet(); };
> |
> ~~^~~
> • note: the operand ‘has_default_pet<T>’ is unsatisfied
> because
> P3358R0.C:19:41:
> 19 | concept pettable = has_member_pet<T> or
> has_default_pet<T>;
> |
> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
> • required for the satisfaction of ‘has_default_pet<T>’
> [with T = lizard]
> P3358R0.C:16:9:
> 16 | concept has_default_pet = T::is_pettable;
> | ^~~~~~~~~~~~~~~
> • required for the satisfaction of ‘pettable<auto:1>’
> [with auto:1 = lizard]
> P3358R0.C:19:9:
> 19 | concept pettable = has_member_pet<T> or
> has_default_pet<T>;
> | ^~~~~~~~
> • error: ‘is_pettable’ is not a member of ‘lizard’
> P3358R0.C:16:30:
> 16 | concept has_default_pet = T::is_pettable;
> | ^~~~~~~~~~~
> • note: candidate: ‘void pet(dog)’
> P3358R0.C:9:6:
> 9 | void pet(dog);
> | ^~~
> • note: no known conversion for argument 1 from ‘lizard’ to ‘dog’
> P3358R0.C:9:10:
> 9 | void pet(dog);
> | ^~~
> • note: candidate: ‘void pet(cat)’
> P3358R0.C:10:6:
> 10 | void pet(cat);
> | ^~~
> • note: no known conversion for argument 1 from ‘lizard’ to ‘cat’
> P3358R0.C:10:10:
> 10 | void pet(cat);
> | ^~~
>
> showing the hierarchical structure of the messages; ideally there
> would be a UI here allowing the user to expand/collapse the messages
> to drill out into the detail they are interested in.
For the curious, I've attached a screenshot of a colorized version of
this to PR other/116253 as:
https://gcc.gnu.org/bugzilla/attachment.cgi?id=59580
Dave