This is an archive of the discontinued LLVM Phabricator instance.

Don't delete default constructor of PathDiagnosticConsumerOptions
ClosedPublic

Authored by MoritzS on Nov 27 2020, 3:35 AM.

Details

Summary

This type is used as an aggregate, i.e. it has no member functions.
Starting with C++20 types with deleted default constructors are not
aggregate types anymore which means that aggregate initialization will
not work for this class anymore. This leads to a compile error in
clang::AnalyzerOptions::getDiagOpts() for example.

Also set the boolean flags to false by default to avoid undefined
behavior. Previously this was prevented by deleting the default
constructor, now we explicitly initialize them.

Diff Detail

Event Timeline

MoritzS created this revision.Nov 27 2020, 3:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 27 2020, 3:35 AM
MoritzS requested review of this revision.Nov 27 2020, 3:35 AM
Charusso edited reviewers, added: NoQ; removed: dergachev.a.Nov 27 2020, 3:38 AM
NoQ accepted this revision.Nov 29 2020, 4:16 PM
NoQ added a reviewer: vsavchenko.

Aha, ok then! Thanks for cleaning this up.

Maybe we should provide default initializers for bool flags then, so that they weren't undefined by default.

clang/include/clang/Analysis/PathDiagnostic.h
71
75
85
89
93
96–97
This revision is now accepted and ready to land.Nov 29 2020, 4:16 PM

Another way to avoid UB in that case is to use value initialization, i.e. PathDiagnosticConsumerOptions options{};.

Can you commit this, please? I don't have commit access.

MoritzS updated this revision to Diff 313145.Dec 21 2020, 10:26 AM

Rebased onto master

MoritzS updated this revision to Diff 318463.Jan 22 2021, 1:51 AM

Rebased onto master, run tests again

vsavchenko accepted this revision.Jan 22 2021, 2:48 AM

Hi @MoritzS thanks for the cleanup!
Maybe while you are on it, you can set default values as pointed by @NoQ?

MoritzS updated this revision to Diff 318477.Jan 22 2021, 2:59 AM
MoritzS edited the summary of this revision. (Show Details)

Initialize bool flags

Some tests were failing, I'll try to fix that and then commit the changes.