Skip to content

GTiff: Avoid value-initialization of vector of forward declared class#14743

Merged
rouault merged 1 commit into
OSGeo:masterfrom
nilason:fix_fwd_decl_issue_gtiff
Jun 8, 2026
Merged

GTiff: Avoid value-initialization of vector of forward declared class#14743
rouault merged 1 commit into
OSGeo:masterfrom
nilason:fix_fwd_decl_issue_gtiff

Conversation

@nilason
Copy link
Copy Markdown
Contributor

@nilason nilason commented Jun 8, 2026

What does this PR do?

Trigger default-initialisation instead of value-initialisation of vector of forward declared class (in frmts/gtiff/gtiffdataset.h).

Addresses "invalid application of 'sizeof' to an incomplete type 'GTiffJPEGOverviewDS'" compiler error on macOS 12 and earlier (with AppleClang 13 and earlier):

In file included from /opt/local/var/macports/build/gdal-ab2406e0/work/gdal-3.13.0/frmts/gtiff/cogdriver.cpp:15:
In file included from /opt/local/var/macports/build/gdal-ab2406e0/work/gdal-3.13.0/gcore/gdalalgorithm.h:16:
In file included from /opt/local/var/macports/build/gdal-ab2406e0/work/gdal-3.13.0/gcore/gdalalgorithm_c.h:19:
In file included from /opt/local/var/macports/build/gdal-ab2406e0/work/gdal-3.13.0/gcore/gdal.h:30:
In file included from /opt/local/var/macports/build/gdal-ab2406e0/work/gdal-3.13.0/port/cpl_error.h:395:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/memory:682:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__memory/shared_ptr.h:25:
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__memory/unique_ptr.h:53:19: error: invalid application of 'sizeof' to an incomplete type 'GTiffJPEGOverviewDS'
    static_assert(sizeof(_Tp) > 0,
                  ^~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__memory/unique_ptr.h:318:7: note: in instantiation of member function 'std::default_delete<GTiffJPEGOverviewDS>::operator()' requested here
      __ptr_.second()(__tmp);
      ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__memory/unique_ptr.h:272:19: note: in instantiation of member function 'std::unique_ptr<GTiffJPEGOverviewDS>::reset' requested here
  ~unique_ptr() { reset(); }
                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__memory/allocator.h:159:15: note: in instantiation of member function 'std::unique_ptr<GTiffJPEGOverviewDS>::~unique_ptr' requested here
        __p->~_Tp();
              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__memory/allocator_traits.h:309:13: note: in instantiation of member function 'std::allocator<std::unique_ptr<GTiffJPEGOverviewDS>>::destroy' requested here
        __a.destroy(__p);
            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/vector:450:25: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<std::unique_ptr<GTiffJPEGOverviewDS>>>::destroy<std::unique_ptr<GTiffJPEGOverviewDS>, void>' requested here
        __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/vector:374:29: note: in instantiation of member function 'std::__vector_base<std::unique_ptr<GTiffJPEGOverviewDS>, std::allocator<std::unique_ptr<GTiffJPEGOverviewDS>>>::__destruct_at_end' requested here
    void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
                            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/vector:487:9: note: in instantiation of member function 'std::__vector_base<std::unique_ptr<GTiffJPEGOverviewDS>, std::allocator<std::unique_ptr<GTiffJPEGOverviewDS>>>::clear' requested here
        clear();
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/vector:519:5: note: in instantiation of member function 'std::__vector_base<std::unique_ptr<GTiffJPEGOverviewDS>, std::allocator<std::unique_ptr<GTiffJPEGOverviewDS>>>::~__vector_base' requested here
    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
    ^
/opt/local/var/macports/build/gdal-ab2406e0/work/gdal-3.13.0/frmts/gtiff/gtiffdataset.h:136:74: note: in instantiation of member function 'std::vector<std::unique_ptr<GTiffJPEGOverviewDS>>::vector' requested here
    std::vector<std::unique_ptr<GTiffJPEGOverviewDS>> m_apoJPEGOverviewDS{};
                                                                         ^
/opt/local/var/macports/build/gdal-ab2406e0/work/gdal-3.13.0/frmts/gtiff/gtiffdataset.h:43:7: note: forward declaration of 'GTiffJPEGOverviewDS'
class GTiffJPEGOverviewDS;
      ^

This wasn't an issue on macOS 13 and newer, I can't test this fix on the failing platform but it compiles fine on macOS 26. I noticed this failure on MacPorts' build logs.

What are related issues/pull requests?

AI tool usage

  • AI (Y-a-t-il-un-Copilot-dans-l'avion, Chat-j'ai-pété, Jean-Claude Dusse or something similar) supported my development of this PR. See our policy about AI tool use. Use of AI tools must be indicated.

Tasklist

  • Make sure code is correctly formatted (cf pre-commit configuration)
  • Add test case(s)
  • Add documentation
  • Updated Python API documentation (swig/include/python/docs/)
  • Review
  • Adjust for comments
  • All CI builds and checks have passed
  • ADD YOUR TASKS HERE

Environment

Provide environment details, if relevant:

  • OS: macOS 12.7.6
  • Compiler: AppleClang 13.1.6.13160021

@nilason
Copy link
Copy Markdown
Contributor Author

nilason commented Jun 8, 2026

Oh, this apparently needs another approach:

/home/runner/work/gdal/gdal/frmts/gtiff/gtiffdataset.cpp:72:1: error: 'GTiffDataset::m_apoJPEGOverviewDS' should be initialized in the member initialization list [-Werror=effc++]
72 | GTiffDataset::GTiffDataset()
| ^~~~~~~~~~~~
/home/runner/work/gdal/gdal/frmts/gtiff/gtiffdataset.cpp:72:1: error: 'GTiffDataset::m_apoJPEGOverviewDSOld' should be initialized in the member initialization list [-Werror=effc++]

Addresses "invalid application of 'sizeof' to an incomplete type 'GTiffJPEGOverviewDS'" compiler
error on macOS 12 and earlier (with AppleClang 13 and earlier).
@nilason nilason force-pushed the fix_fwd_decl_issue_gtiff branch from 04e3c5a to 3249338 Compare June 8, 2026 08:39
@nilason
Copy link
Copy Markdown
Contributor Author

nilason commented Jun 8, 2026

Now I believe it should be ok.

@rouault rouault merged commit 9f1da7a into OSGeo:master Jun 8, 2026
35 of 36 checks passed
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 this pull request may close these issues.

2 participants