This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Make SymbolLocation => bool conversion explicitly.
ClosedPublic

Authored by hokein on Jul 22 2018, 11:38 PM.

Details

Summary

The implicit bool conversion could happen superisingly, e.g. when
checking if (Loc1 == Loc2), the compiler will convert SymbolLocation to
bool before comparing (because we don't define operator == for SymbolLocation).

Diff Detail

Event Timeline

hokein created this revision.Jul 22 2018, 11:38 PM
ilya-biryukov accepted this revision.Jul 23 2018, 4:55 AM

Scary....
Definitely LGTM!

clangd/index/Index.h
45–49

Maybe we should go even further and replace this with an isValid method? Conversion ops are confusing.

This revision is now accepted and ready to land.Jul 23 2018, 4:55 AM

Or make operator bool explicit

hokein marked an inline comment as done.Aug 1 2018, 4:24 AM
hokein added inline comments.
clangd/index/Index.h
45–49

I think making the bool operator explicit is sufficient to avoid the scary implicit-conversion problem.

This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.