Skip to content

diagnostic divergence between -std=c++20 and -std=c++17 when referencing member of std::vector of incomplete type #60522

@ldalessa

Description

@ldalessa

In the following code example, I perform a value initialization of a std::vector of incomplete type.

#include <vector>

struct B;

struct A {
    std::vector<B> _;
};

A a{};  // <--here

struct B {};

https://godbolt.org/z/ab5Erqc1n

This runs afoul of the second half of https://eel.is/c++draft/vector#overview-4. "T shall be complete before any member of the resulting specialization of vector is referenced." I do not know if this is ill-formed or undefined behavior.

Staring in clang-15, this is diagnosed as invalid, but only with -std=c++20. Thisimplies to me that this diagnostic is probably incidental. For consistency it would be helpful if this diagnostic could be emitted for all standard versions, as a Quality of Implementation improvement.

As a reference I have added https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108669 to normalize this diagnostic across clang and gcc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions