How to raise a warning when using the default constructor directly?

The first idea which comes to my mind is to add a keyword argument to your inner constructor which mutes the warning (punintented).

struct Foo
	a::Int
	b::Int
	c::Int
	function Foo(a::Int, b::Int; warnifused=true)
		warnifused && @warn "You should use a custom constructor!"
		return new(a, b, a + b)
	end
end

and then

function custom_constructor_1(;
		a::Int = 5,
		b::Int = 8,
	)
	@info "Good, you use custom constructor № 1"
	println("a=$a, b=$b")
	return Foo(a, b; warnifused=false)
end
2 Likes