llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.14k stars 12.02k forks source link

clang-tidy 13.0.1 suggests fixes which may break code #56372

Open themightyoarfish opened 2 years ago

themightyoarfish commented 2 years ago

clang-tidy will suggest to change code like this

std::shared_ptr<Foo> foo ...;
…
foo.reset(new Foo);

to

std::shared_ptr<Foo> foo ...;
…
foo = std::make_shared<Foo>(…);

However, make_shared does not respect custom alignment requirements which the Foo type may have. new should do that, from what I understand. This is an issue at least in C++14.

For reference, the tidy file is here. I assume +modernize-make-shared is the reason, but should this even be an option to misalign memory potentially?

# FormatStyle: file
InheritParentConfig: false
User: user
AnalyzeTemporaryDtors: false
WarningsAsErrors: >
  -bugprone-argument-comment
CheckOptions:
  - key: readability-implicit-bool-conversion.AllowPointerConditions
    value: true
  - key: readability-implicit-bool-conversion.AllowIntegerConditions
    value: true
  - key: performance-unnecessary-value-param.AllowedTypes
    value: "[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;iterator$"
  - key: performance-unnecessary-copy-initialization.AllowedTypes
    value: "[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;iterator$"
  - key: performance-for-range-copy.AllowedTypes
    value: "[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;iterator$"

# HeaderFilterRegex: src
# List of checks: https://clang.llvm.org/extra/clang-tidy/checks/list.html
Checks: >
  clang-diagnostic-*,
  clang-analyzer-*,
  -*,
  boost-*,
  readability-*,
  -readability-avoid-const-params-in-decls,
  readability-const-return-type,
  readability-container-size-empty,
  -readability-convert-member-functions-to-static,
  -readability-delete-null-pointer,
  -readability-else-after-return,
  -readability-function-cognitive-complexity,
  -readability-function-size,
  -readability-inconsistent-declaration-parameter-name,
  -readability-isolate-declaration,
  -readability-magic-numbers,
  readability-make-member-function-const,
  -readability-named-parameter,
  readability-qualified-auto,
  -readability-redundant-control-flow,
  -readability-redundant-declaration,
  -readability-redundant-member-init,
  -readability-redundant-string-init,
  -readability-simplify-boolean-expr,
  readability-static-accessed-through-instance,
  readability-suspicious-call-argument,
  -readability-uppercase-literal-suffix,
  -readability-use-anyofallof,
  readability-braces-around-statements,
  -readability-implicit-bool-conversion,
  readability-redundant-string-cstr,
  modernize-*,
  -modernize-avoid-bind,
  -modernize-avoid-c-arrays,
  modernize-deprecated-headers,
  -modernize-loop-convert,
  +modernize-make-shared,
  +modernize-make-unique,
  -modernize-pass-by-value,
  -modernize-raw-string-literal,
  -modernize-redundant-void-arg,
  -modernize-return-braced-init-list,
  -modernize-use-auto,
  modernize-use-bool-literals,
  -modernize-use-default-member-init,
  modernize-use-emplace,
  -modernize-use-equals-default,
  -modernize-use-equals-delete,
  modernize-use-nullptr,
  modernize-use-override,
  -modernize-use-trailing-return-type,
  -modernize-use-transparent-functors,
  -modernize-use-using,
  bugprone-*,
  -bugprone-branch-clone,
  -bugprone-easily-swappable-parameters,
  -bugprone-exception-escape,
  -bugprone-implicit-widening-of-multiplication-result,
  -bugprone-integer-division,
  -bugprone-macro-parentheses,
  -bugprone-narrowing-conversions,
  -bugprone-reserved-identifier,
  -bugprone-string-integer-assignment,
  bugprone-suspicious-include,
  -bugprone-unhandled-exception-at-new,
  bugprone-argument-comment,
  -cppcoreguidelines-prefer-member-initializer,
  cppcoreguidelines-virtual-class-destructor,
  performance-*,
  cert-dcl21-cpp,
  -cppcoreguidelines-init-variables,

# Checks listed below are currently disabled above, but one cannot leave
# comments in a multiline string.. So they are listed here again with somments
# whether they should be enabled.

# -readability-avoid-const-params-in-decls # want?
# -readability-convert-member-functions-to-static # want!
# -readability-delete-null-pointer # want
# -readability-else-after-return # want
# -readability-function-cognitive-complexity
# -readability-function-size
# -readability-inconsistent-declaration-parameter-name # want
# -readability-isolate-declaration # want
# -readability-magic-numbers
# -readability-named-parameter # want?
# -readability-redundant-control-flow # want
# -readability-redundant-declaration # want
# -readability-redundant-member-init
# -readability-redundant-string-init # want
# -readability-simplify-boolean-expr # want
# -readability-uppercase-literal-suffix # want
# -readability-use-anyofallof
# -cppcoreguidelines-prefer-member-initializer # want
# "-performance-*" # want?
# -bugprone-branch-clone # want
# -bugprone-easily-swappable-parameters # we should use this!
# -bugprone-exception-escape # want!
# -bugprone-implicit-widening-of-multiplication-result # want
# -bugprone-integer-division # want!
# -bugprone-macro-parentheses
# -bugprone-narrowing-conversions # want
# -bugprone-reserved-identifier
# -bugprone-string-integer-assignment # want!
# -bugprone-suspicious-include # want
# -bugprone-unhandled-exception-at-new
# -modernize-avoid-bind # want?
# -modernize-avoid-c-arrays # want?
# -modernize-loop-convert # want
# -modernize-make-shared # want?
# -modernize-make-unique # want?
# -modernize-pass-by-value
# -modernize-raw-string-literal # want
# -modernize-redundant-void-arg # want
# -modernize-return-braced-init-list
# -modernize-use-auto
# -modernize-use-bool-literals # want
# -modernize-use-default-member-init # want!
# -modernize-use-emplace # want
# -modernize-use-equals-default # want
# -modernize-use-equals-delete # want
# -modernize-use-nullptr # want
# -modernize-use-trailing-return-type
# -modernize-use-transparent-functors
# -modernize-use-using # want
# # want, but produces too many static_cast atm with AC_DL
# -readability-implicit-bool-conversion
EugeneZelenko commented 2 years ago

Could you please try main? https://godbolt.org should be helpful.

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-tidy