[cfe-dev] clang-format bug with u8 character literal

Nico Weber via cfe-dev cfe-dev at lists.llvm.org
Fri Mar 10 15:03:59 PST 2017


The patch you posted looks good to me. Can you add a test to
unittests/Format/FormatTest.cpp too? (Run tests with `ninja FormatTests &&
./tools/clang/unittests/Format/FormatTests`).


On Fri, Mar 10, 2017 at 4:52 PM, via cfe-dev <cfe-dev at lists.llvm.org> wrote:

> Seems like fix is very simple, clang-format currently does not respect
> c++1z at all. With patch below I could verify that it can recognize u8'a'
> as utf8 character literal. Without it it recognize it as two tokens:
> identifier and character literal.
> My guess that .clang-format should allow to specify LanguageStandard:
> LS_Cpp17 now, does it sound good? I can try to contribute to clang-format -
> that will be the first time for me - will be happy to try it out.
>
> tools/clang
>                                                           ✓  13:45:12
> ╰─ svn diff
> Index: lib/Format/Format.cpp
> ===================================================================
> --- lib/Format/Format.cpp (revision 297506)
> +++ lib/Format/Format.cpp (working copy)
> @@ -1893,6 +1893,7 @@
>    LangOpts.CPlusPlus = 1;
>    LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
>    LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
> +  LangOpts.CPlusPlus1z = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
>    LangOpts.LineComment = 1;
>    bool AlternativeOperators = Style.IsCpp();
>    LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
>
>
>
> On Mar 10, 2017, at 11:09 AM, via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>
> Hi all,
>
> clang-format does not work well with character literal u8 ' c-char '.
> Example
>
> clang-format <<END
> auto c1 = u8'a';
> auto c2 = u'a';
> END
>
> Produces
>
> auto c1 = u8 'a';
> auto c2 = u'a';
>
> As you can see clang-format adds an additional space between u8 and 'a'.
>
> clang-format --version
> clang-format version 4.0.0 (http://llvm.org/git/clang.git
> 559aa046fe3260d8640791f2249d7b0d458b5700) (http://llvm.org/git/llvm.git
> 4423e351176a92975739dd4ea43c2ff5877236ae)
>
> Not sure if this is the best place to report a bug.
>
> Thanks,
> Denis Gladkikh
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170310/db0a6603/attachment.html>


More information about the cfe-dev mailing list