Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation fails on broken optional_container_property template with latest Clang #136

Open
mstorsjo opened this issue May 6, 2024 · 0 comments · May be fixed by #137
Open

Compilation fails on broken optional_container_property template with latest Clang #136

mstorsjo opened this issue May 6, 2024 · 0 comments · May be fixed by #137

Comments

@mstorsjo
Copy link

mstorsjo commented May 6, 2024

Since llvm/llvm-project#84050 and llvm/llvm-project#90152, Clang will issue diagnostics about invalid member accesses in a class template, even before the class is instantiated.

This uncovers an issue in asdcplib, which ends up in compile errors like these:

In file included from asdcplib/src/TimedText_Parser.cpp:33:
In file included from asdcplib/src/AS_DCP_internal.h:38:
In file included from asdcplib/src/Metadata.h:35:
asdcplib/src/MXF.h:276:12: error: no member named 'Copy' in 'optional_container_property<PropertyType>'
  276 |             this->Copy(rhs.m_property);
      |             ~~~~  ^
asdcplib/src/MXF.h:284:48: error: no member named 'clear' in 'optional_container_property<PropertyType>'
  284 |           void reset(const PropertyType& rhs) { this->clear(); }
      |                                                 ~~~~  ^
2 errors generated.

The relevant code at hand looks like this:

      // wrapper object manages optional properties
      template <class PropertyType>
        class optional_container_property
        { 
          PropertyType m_property;
          
        public:
          optional_container_property() {}
        optional_container_property(const PropertyType& value) : m_property(value) {}     
          const optional_container_property<PropertyType>& operator=(const PropertyType& rhs) {
            this->Copy(rhs.m_property);
            return *this;
          }
          
          bool operator==(const PropertyType& rhs) const { return this->m_property == rhs; }
          bool operator==(const optional_property<PropertyType>& rhs) const { return this->m_property == rhs.m_property; }
          operator PropertyType&() { return this->m_property; }
          void set(const PropertyType& rhs) { this->m_property = rhs; }
          void reset(const PropertyType& rhs) { this->clear(); }
          bool empty() const { return ! this->m_property.HasValue(); }
          PropertyType& get() { return m_property; }
          const PropertyType& const_get() const { return m_property; }
        };

https://github.com/cinecert/asdcplib/blob/master/src/MXF.h#L266-L288

The this->Copy() and this->clear() method calls do look like a valid error as there are no such members defined here. This hasn't been an issue before as this class doesn't seem to be actually used anywhere.

I can make a PR to just outright remove this unused template class, to fix compilation that way, but would you have a preference to fix the code differently somehow? This code seems to stem from 0291582, and does seem to have the same references to nonexistent members even back then.

mstorsjo added a commit to mstorsjo/asdcplib that referenced this issue May 7, 2024
Since Clang changes
llvm/llvm-project#84050 and
llvm/llvm-project#90152 (upcoming in
Clang 19.x), Clang will diagnose member accesses before instantiating
C++ templates.

Within the optional_container_property template, this causes errors
for the calls to this->Copy() and this->clear(), as there are no
corresponding methods within that template class, errors like these:

    asdcplib/src/MXF.h:276:12: error: no member named 'Copy' in 'optional_container_property<PropertyType>'
      276 |             this->Copy(rhs.m_property);
          |             ~~~~  ^
    asdcplib/src/MXF.h:284:48: error: no member named 'clear' in 'optional_container_property<PropertyType>'
      284 |           void reset(const PropertyType& rhs) { this->clear(); }
          |                                                 ~~~~  ^

This template is unused, and these faulty calls have been present
since the class was added in 0291582.

Simply remove the unused template class, to avoid these compiler
errors.

This fixes cinecert#136.
@mstorsjo mstorsjo linked a pull request May 7, 2024 that will close this issue
dheitmueller pushed a commit to LTNGlobal-opensource/vlc-3.0 that referenced this issue May 24, 2024
The asdcplib code contains a C++ template which refers to member
variables that doesn't exist. Earlier, this hasn't been an issue,
as the C++ template never is instantiated, but current Clang
versions (the upcoming 19.x version) diagnoses such issues already
before the class is instantiated, leading to compilation errors
on the asdcplib code.

This applies cinecert/asdcplib#137 (which
hasn't yet received any attention), fixing
cinecert/asdcplib#136.

(cherry picked from commit c481befc9796ed57606d5fd7cba18449702d4cc2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant