GNU bug report logs - #62386
CC Mode 5.35.2 (C++//l); C++ concept indentation

Previous Next

Package: cc-mode;

Reported by: Michael Welsh Duggan <mwd <at> md5i.com>

Date: Wed, 22 Mar 2023 15:59:01 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 62386 <at> debbugs.gnu.org (full text, mbox):

From: Michael Welsh Duggan <mwd <at> md5i.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Michael Welsh Duggan <mwd <at> md5i.com>, 62386 <at> debbugs.gnu.org
Subject: Re: bug#62386: CC Mode 5.35.2 (C++//l); C++ concept indentation
Date: Fri, 24 Mar 2023 14:58:28 -0400
Alan Mackenzie <acm <at> muc.de> writes:

> On Wed, Mar 22, 2023 at 11:58:32 -0400, Michael Welsh Duggan wrote:
>> Package: cc-mode
>
>> Given a concept definition like:
>
>>     template <typename T>
>>     concept Foo =
>>       Bar<T>
>>       && requires (T t) {
>>         { t + t } -> std::same_as<T>;
>>       }
>>       && something_else;
>
>> This is how it actually indents in cc-mode:
>
>>     template <typename T>
>>     concept Foo =
>>     Bar<T>
>>       && requires (T t) {
>>       { t + t } -> std::same_as<T>;
>>     }
>>       && something_else;
>
>> I would expect "Bar<T>" to be statement-cont, but it is
>> topmost-intro-cont instead.  The indentation of "{ t + t }" isn't offset
>> properly with respect to the "requires" clause, and the closing brace is
>> way out of line.

[...]

> I've made an attempt to improve the indentation of code like your test
> case.  Would you please try it out and let me know how well it solves
> the problem.  Thanks!

Better for that test case and a few others.  Here's a few test outliers
as indented by cc:

template <typename T>
concept Foo2 =
requires (T t) {
  *t -> std::same_as<int>; 
  *(t + t) -> std::same_as<int>; 
};
  
template <typename T>
concept Foo5 = 
  Foo<T>
  && requires (T t)
{
    { t++; }
  };

and how I would expect them to be indented:

template <typename T>
concept Foo2 =
  requires (T t) {
    *t -> std::same_as<int>; 
    *(t + t) -> std::same_as<int>; 
  };
  
template <typename T>
concept Foo5 = 
  Foo<T>
  && requires (T t)
  {
    { t++; }
  };

Here's some requires clause cases outside of concepts:

template <typename T>
requires Bar<T>
&& Baz<T>
int foo();

template <typename T>
requires 
(requires (T t) { ++t; }
&& Baz<T>)
int foo();

and how I would expect them to be indented:

template <typename T>
requires Bar<T>
  && Baz<T>
int foo();

template <typename T>
requires 
  (requires (T t) { ++t; }
   && Baz<T>)
int foo();

The latter of these is especially interesting because TAB on the "&&
Baz<T>)" section causes an "End of buffer" signal.

-- 
Michael Welsh Duggan
(md5i <at> md5i.com)




This bug report was last modified 2 years and 34 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.