This is an archive of the discontinued LLVM Phabricator instance.

Improve literal operator parameter diagnostics.
ClosedPublic

Authored by erik.pilkington on Feb 5 2016, 10:32 AM.

Details

Reviewers
rsmith
Summary

Previously, invalid parameters in a literal operator function were diagnosed with an uninformative catch all. This commit breaks the catch all into a couple of more informative cases.

Diff Detail

Event Timeline

erik.pilkington retitled this revision from to Improve literal operator parameter diagnostics..
erik.pilkington updated this object.
erik.pilkington added a reviewer: rsmith.
erik.pilkington added a subscriber: cfe-commits.
rsmith edited edge metadata.Feb 5 2016, 11:36 AM

Thanks for tackling this!

include/clang/Basic/DiagnosticSemaKinds.td
6891

Maybe "parameter of literal operator must have type 'unsigned long long', 'long double', 'char', 'wchar_t', 'char16_t', or 'char32_t'"?

6897

on -> for ?

6899

It'd be nice to say what the valid ones are here. "template parameter list for literal operator must be either 'char...' or 'typename T, T...'" maybe?

lib/Sema/SemaDeclCXX.cpp
11798–11825

Factor out an isValidLiteralOperatorTemplateParameterList function to avoid the somewhat-unclear control flow via goto here.

11827–11831

Please invert the sense of the param_size() == 0 test and move this up to the top, so it's right next to the condition that the diagnostic is diagnosing.

11846–11847

Replace these two with ParamType->isSpecificBuiltinType(BuiltinType::ULongLong) and ParamType->isSpecificBuiltinType(BuiltinType::LongDouble).

11871–11874

I don't think this special case is worthwhile. Merge it with the _invalid_param case.

erik.pilkington edited edge metadata.

Thanks! This update fixes everything you brought up.

Thanks, this looks good. I think we can make the control flow a little more obvious by moving the return true;s right after we emit each diagnostic, and that also lets us remove the goto.

lib/Sema/SemaDeclCXX.cpp
11769

If you're going to issue diagnostics from here, it'd be clearer to name this checkLiteralOperator[...].

11891–11892

Move the return true; up into the individual cases that bail out, and remove the goto from the success cases.

11894

Drop this goto, we fall through to the same place.

Remove the FinishedParams label, clean up the control flow.

rsmith accepted this revision.Feb 8 2016, 4:06 PM
rsmith edited edge metadata.

Looks great, thanks, do you need someone to commit this for you?

This revision is now accepted and ready to land.Feb 8 2016, 4:06 PM

Yes I do, if you don't mind. Thanks for your help!

rsmith closed this revision.Feb 16 2016, 4:08 PM

Committed as r261034.