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

classes are instantiated despite explicit instantiations #1334

Open
Raildex opened this issue Jan 15, 2025 · 0 comments
Open

classes are instantiated despite explicit instantiations #1334

Raildex opened this issue Jan 15, 2025 · 0 comments

Comments

@Raildex
Copy link

Raildex commented Jan 15, 2025

I have a header file vector4.h which contains the following:

#ifndef SRC_COMMON_VECTOR4_H
#define SRC_COMMON_VECTOR4_H
#include <glm/vec4.hpp>
#include <glm/gtc/quaternion.hpp>
namespace glm {
	extern template struct qua<float>;
	extern template struct vec<4, float, glm::defaultp>;
	extern template struct vec<4, long long, glm::defaultp>;
	extern template struct vec<4, long, glm::defaultp>;
	extern template struct vec<4, int, glm::defaultp>;
	extern template struct vec<4, unsigned long long, glm::defaultp>;
	extern template struct vec<4, unsigned long, glm::defaultp>;
	extern template struct vec<4, unsigned int, glm::defaultp>;
	extern template struct vec<4, short, glm::defaultp>;
	extern template struct vec<4, unsigned short, glm::defaultp>;
	extern template struct vec<4, signed char, glm::defaultp>;
	extern template struct vec<4, unsigned char, glm::defaultp>;
}
namespace raid {
	namespace math = ::glm;
	using quat = math::qua<float>;
	using float4 = math::vec<4, float, glm::defaultp>;
	using longlong4 = math::vec<4, long long, glm::defaultp>;
	using long4 = math::vec<4, long, glm::defaultp>;
	using int4 = math::vec<4, int, glm::defaultp>;
	using ulonglong4 = math::vec<4, unsigned long long, glm::defaultp>;
	using ulong4 = math::vec<4, unsigned long, glm::defaultp>;
	using uint4 = math::vec<4, unsigned int, glm::defaultp>;
	using short4 = math::vec<4, short, glm::defaultp>;
	using ushort4 = math::vec<4, unsigned short, glm::defaultp>;
	using byte4 = math::vec<4, signed char, glm::defaultp>;
	using ubyte4 = math::vec<4, unsigned char, glm::defaultp>;

} // namespace raid

#endif// SRC_COMMON_VECTOR4_H

I also have a corresponding vector4.cpp:

#include "common/vector4.h"
namespace glm {
	template struct qua<float>;
	template struct vec<4, float, glm::defaultp>;
	template struct vec<4, long long, glm::defaultp>;
	template struct vec<4, long, glm::defaultp>;
	template struct vec<4, int, glm::defaultp>;
	template struct vec<4, unsigned long long, glm::defaultp>;
	template struct vec<4, unsigned long, glm::defaultp>;
	template struct vec<4, unsigned int, glm::defaultp>;
	template struct vec<4, short, glm::defaultp>;
	template struct vec<4, unsigned short, glm::defaultp>;
	template struct vec<4, signed char, glm::defaultp>;
	template struct vec<4, unsigned char, glm::defaultp>;
}

However, the explicit instantiations do not seem to work (as I would expect them to).
Because whenever vector4.h gets included, glm automatically instantiates vec<4,T> in every combination.

I would expect my compiler to generate only one instantiation for the variations I specified in vector4.cpp.

main.cpp.json

Here is a trace of a file.

As you can see, the compiler (clang-cl in my case) instantiates all vector4's:
image

Is there a way to avoid this?

These are my glm compile defines:

GLM_FORCE_MESSAGES
GLM_FORCE_CXX98
GLM_FORCE_PURE
GLM_FORCE_LEFT_HANDED
GLM_FORCE_SWIZZLE
GLM_ENABLE_EXPERIMENTAL
GLM_FORCE_INLINE
GLM_FORCE_DEPTH_ZERO_TO_ONE
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

No branches or pull requests

1 participant