[clang] [clang] Force AttributedStmtClass to not be scope parents (PR #125370)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 10 08:21:15 PST 2025
================
@@ -121,6 +121,186 @@ Attribute Changes in Clang
Improvements to Clang's diagnostics
-----------------------------------
+- Some template related diagnostics have been improved.
+
+ .. code-block:: c++
+
+ void foo() { template <typename> int i; } // error: templates can only be declared in namespace or class scope
+
+ struct S {
+ template <typename> int i; // error: non-static data member 'i' cannot be declared as a template
+ };
+
+- Clang now has improved diagnostics for functions with explicit 'this' parameters. Fixes #GH97878
+
+- Clang now diagnoses dangling references to fields of temporary objects. Fixes #GH81589.
+
+- Clang now diagnoses undefined behavior in constant expressions more consistently. This includes invalid shifts, and signed overflow in arithmetic.
+
+- -Wdangling-assignment-gsl is enabled by default.
+- Clang now always preserves the template arguments as written used
+ to specialize template type aliases.
+
+- Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid according to [basic.start.main] p3. Fixes #GH101512.
+
+- Clang now diagnoses when the result of a [[nodiscard]] function is discarded after being cast in C. Fixes #GH104391.
+
+- Don't emit duplicated dangling diagnostics. (#GH93386).
+
+- Improved diagnostic when trying to befriend a concept. (#GH45182).
+
+- Added the ``-Winvalid-gnu-asm-cast`` diagnostic group to control warnings
+ about use of "noop" casts for lvalues (a GNU extension). This diagnostic is
+ a warning which defaults to being an error, is enabled by default, and is
+ also controlled by the now-deprecated ``-fheinous-gnu-extensions`` flag.
+
+- Added the ``-Wdecls-in-multiple-modules`` option to assist users to identify
+ multiple declarations in different modules, which is the major reason of the slow
+ compilation speed with modules. This warning is disabled by default and it needs
+ to be explicitly enabled or by ``-Weverything``.
+
+- Improved diagnostic when trying to overload a function in an ``extern "C"`` context. (#GH80235)
+
+- Clang now respects lifetimebound attribute for the assignment operator parameter. (#GH106372).
+
+- The lifetimebound and GSL analysis in clang are coherent, allowing clang to
+ detect more use-after-free bugs. (#GH100549).
+
+- Clang now diagnoses dangling cases where a gsl-pointer is constructed from a gsl-owner object inside a container (#GH100384).
+
+- Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``.
+
+- Clang now diagnose when importing module implementation partition units in module interface units.
+
+- Don't emit bogus dangling diagnostics when ``[[gsl::Owner]]`` and `[[clang::lifetimebound]]` are used together (#GH108272).
+
+- The ``-Wreturn-stack-address`` warning now also warns about addresses of
+ local variables passed to function calls using the ``[[clang::musttail]]``
+ attribute.
+
+- Clang now diagnoses cases where a dangling ``GSLOwner<GSLPointer>`` object is constructed, e.g. ``std::vector<string_view> v = {std::string()};`` (#GH100526).
+
+- Clang now diagnoses when a ``requires`` expression has a local parameter of void type, aligning with the function parameter (#GH109831).
+
+- Clang now emits a diagnostic note at the class declaration when the method definition does not match any declaration (#GH110638).
+
+- Clang now omits warnings for extra parentheses in fold expressions with single expansion (#GH101863).
+
+- The warning for an unsupported type for a named register variable is now phrased ``unsupported type for named register variable``,
+ instead of ``bad type for named register variable``. This makes it clear that the type is not supported at all, rather than being
+ suboptimal in some way the error fails to mention (#GH111550).
+
+- Clang now emits a ``-Wdepredcated-literal-operator`` diagnostic, even if the
+ name was a reserved name, which we improperly allowed to suppress the
+ diagnostic.
+
+- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables (#GH90073).
+
+- Fix false positives when `[[gsl::Owner/Pointer]]` and `[[clang::lifetimebound]]` are used together.
+
+- Improved diagnostic message for ``__builtin_bit_cast`` size mismatch (#GH115870).
+
+- Clang now omits shadow warnings for enum constants in separate class scopes (#GH62588).
+
+- When diagnosing an unused return value of a type declared ``[[nodiscard]]``, the type
+ itself is now included in the diagnostic.
+
+- Clang will now prefer the ``[[nodiscard]]`` declaration on function declarations over ``[[nodiscard]]``
+ declaration on the return type of a function. Previously, when both have a ``[[nodiscard]]`` declaration attached,
+ the one on the return type would be preferred. This may affect the generated warning message:
+
+ .. code-block:: c++
+
+ struct [[nodiscard("Reason 1")]] S {};
+ [[nodiscard("Reason 2")]] S getS();
+ void use()
+ {
+ getS(); // Now diagnoses "Reason 2", previously diagnoses "Reason 1"
+ }
+
+- Clang now diagnoses ``= delete("reason")`` extension warnings only in pedantic mode rather than on by default. (#GH109311).
+
+- Clang now diagnoses missing return value in functions containing ``if consteval`` (#GH116485).
+
+- Clang now correctly recognises code after a call to a ``[[noreturn]]`` constructor
+ as unreachable (#GH63009).
+
+- Clang now omits shadowing warnings for parameter names in explicit object member functions (#GH95707).
+
+- Improved error recovery for function call arguments with trailing commas (#GH100921).
+
+- For an rvalue reference bound to a temporary struct with an integer member, Clang will detect constant integer overflow
+ in the initializer for the integer member (#GH46755).
+
+- Fixed a false negative ``-Wunused-private-field`` diagnostic when a defaulted comparison operator is defined out of class (#GH116961).
+
+- Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957).
+
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class
+ defined a defaulted comparison operator (#GH116270).
+
+ .. code-block:: c++
+
+ class A {
+ private:
+ int a; // warning: private field 'a' is not used, no diagnostic previously
+ };
+
+ class C {
+ bool operator==(const C&) = default;
+ };
+
+- Clang now emits `-Wdangling-capture` diangostic when a STL container captures a dangling reference.
+
+ .. code-block:: c++
+
+ void test() {
+ std::vector<std::string_view> views;
+ views.push_back(std::string("123")); // warning
+ }
+
+- Clang now emits a ``-Wtautological-compare`` diagnostic when a check for
+ pointer addition overflow is always true or false, because overflow would
+ be undefined behavior.
+
+ .. code-block:: c++
+
+ bool incorrect_overflow_check(const char *ptr, size_t index) {
+ return ptr + index < ptr; // warning
+ }
+
+- Fix -Wdangling false positives on conditional operators (#120206).
+
+- Fixed a bug where Clang hung on an unsupported optional scope specifier ``::`` when parsing
+ Objective-C. Clang now emits a diagnostic message instead of hanging.
+
+- The :doc:`ThreadSafetyAnalysis` now supports passing scoped capabilities into functions:
+ an attribute on the scoped capability parameter indicates both the expected associated capabilities and,
+ like in the case of attributes on the function declaration itself, their state before and after the call.
+
+ .. code-block:: c++
+
+ #include "mutex.h"
+
+ Mutex mu1, mu2;
+ int a GUARDED_BY(mu1);
+
+ void require(MutexLocker& scope REQUIRES(mu1)) {
+ scope.Unlock();
+ a = 0; // Warning! Requires mu1.
+ scope.Lock();
+ }
+
+ void testParameter() {
+ MutexLocker scope(&mu1), scope2(&mu2);
+ require(scope2); // Warning! Mutex managed by 'scope2' is 'mu2' instead of 'mu1'
+ require(scope); // OK.
+ scope.Unlock();
+ require(scope); // Warning! Requires mu1.
+ }
+
+- Clang now forces attributes to not be scope parents (#84072).
----------------
AaronBallman wrote:
```suggestion
- A statement attribute applied to a ``case`` label no longer suppresses
'bypassing variable initialization' diagnostics (#84072).
```
https://github.com/llvm/llvm-project/pull/125370
More information about the cfe-commits
mailing list