Skip to content

fix: demo no longer links an excluded type when IMPLOT_CUSTOM_NUMERIC_TYPES is restricted - #726

Merged
brenocq merged 3 commits into
masterfrom
fix/custom-numeric-types-demo-link
Oct 25, 2026
Merged

brenocq merged 3 commits into
masterfrom
fix/custom-numeric-types-demo-link

Conversation

@brenocq

@brenocq brenocq commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #715

Building the example with a restricted IMPLOT_CUSTOM_NUMERIC_TYPES, e.g. -DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)" (the way implot.h suggests for shrinking the binary), compiles implot_demo.cpp but then fails to link. A few demos hardcode their data as ImS8, int or unsigned int to show that PlotXxx() is not limited to float/double, and ImPlot only instantiates PlotXxx<T> for the types in IMPLOT_NUMERIC_TYPES:

undefined reference to `void ImPlot::PlotBars<signed char>(char const*, signed char const*, int, double, double, ImPlotSpec const&)'
undefined reference to `void ImPlot::PlotBarGroups<signed char>(...)'

This PR makes the demo gate those snippets at compile time. The type list (IMPLOT_CUSTOM_NUMERIC_TYPES if defined, otherwise all ten types) is defined once as IMPLOT_NUMERIC_TYPES in implot_internal.h, moved there from implot_items.cpp. implot_demo.cpp gets a small "Numeric Type Gating" section that reads it, and an IMPLOT_DEMO_TYPE_GATED(Name) macro. It declares Name<T>() as two SFINAE overloads: the real body when T is enabled, and a one-line notice when it is not. The disabled overload never references PlotXxx<T>, so the linker never looks for it. The affected demos are Bar Plots, Bar Groups, Bar Stacks, the second Pie Chart, Markers and Text, Colorful Bars (Per-Index Colors), Linked Axes and the Seaborn style (Custom Styles). The list is also documented next to its definition, noting that the define must reach implot_demo.cpp too and that the demo needs float and double in it. A new Linux CI job builds and runs example_implot with (float)(double), so a demo that needs another type without being gated now fails to link there. With the default type list nothing changes: each demo calls the same code with the same type as before.

Before:

void Demo_BarPlots() {
    IMGUI_DEMO_MARKER("Plots/Bar Plots");
    static ImS8 data[10] = {1,2,3,4,5,6,7,8,9,10};
    ...
}

After:

IMPLOT_DEMO_TYPE_GATED(Demo_BarPlots_) {
    static T data[10] = {1,2,3,4,5,6,7,8,9,10};
    ...
}

void Demo_BarPlots() {
    IMGUI_DEMO_MARKER("Plots/Bar Plots");
    Demo_BarPlots_<ImS8>();
}

When the type is excluded, the demo shows:

void ShowTypeDisabledNotice() {
    ImGui::TextDisabled("(this demo needs a numeric type excluded via IMPLOT_CUSTOM_NUMERIC_TYPES)");
}

Tested by building example/ against ImGui v1.93.0 with (float)(double) (fails to link before this change, links after) and with the default types (unchanged).

Bar Plots, the second Pie Chart and Linked Axes, in the default build and with (float)(double):

default types (float)(double)
image image
image image
image image

@brenocq brenocq added type:fix Something isn't working prio:high High priority status:review The task is under review labels Oct 10, 2026
@brenocq brenocq self-assigned this Oct 25, 2026
…_TYPES is restricted

A handful of demos (Bar Plots, Bar Groups, Bar Stacks, the second Pie Chart,
Markers and Text, the "Colorful Bar Plots" bit of Per-Index Colors, Linked
Axes, and the Seaborn style bit of Custom Styles) hardcode their plot data as
ImS8, int or unsigned int just to show that PlotXxx() isn't limited to
float/double. Since ImPlot only explicitly instantiates PlotXxx<T> for the
types listed in IMPLOT_NUMERIC_TYPES, building with
-DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)" (as suggested in implot.h's
own docs for shrinking the binary) made these calls fail to link with
undefined references, even though they compiled fine.

Rather than silently swapping each demo's data to a fallback type, which
would be confusing in its own way, this mirrors the numeric type list inside
implot_demo.cpp and uses it to gate those specific snippets at compile time:
a small SFINAE helper picks between the real snippet and a one-line "type
excluded" notice depending on whether the hardcoded type is actually
instantiated, so the excluded overload never references the unavailable
PlotXxx<T> and the linker never looks for it. The default type list is
untouched, so normal builds keep calling the exact same code they always did.
The IMPLOT_NUMERIC_TYPES definition (IMPLOT_CUSTOM_NUMERIC_TYPES if set,
otherwise the ten default types), with its explanatory comment, moves from
implot_items.cpp into implot_internal.h so the library and the demo read the
same list.

The demo's gating helpers now walk IMPLOT_NUMERIC_TYPES directly instead of
keeping their own copy of the list that had to stay in sync by hand, and
implot_demo.cpp includes implot_internal.h at the top for it.
Every existing CI job builds with the "all types" list, so nothing noticed when a demo
needed a type that a restricted list leaves out. Add a Linux job that builds and runs
example_implot with -DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)".

A demo that plots non-float/double data and is not declared with IMPLOT_DEMO_TYPE_GATED
now fails to link in this job.
@brenocq
brenocq force-pushed the fix/custom-numeric-types-demo-link branch from 98d696b to f694fdd Compare October 25, 2026 07:52
@brenocq
brenocq merged commit ea74b04 into master Oct 25, 2026
38 checks passed
@brenocq brenocq added status:done Task completed successfully and removed status:review The task is under review labels Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prio:high High priority status:done Task completed successfully type:fix Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Using -DIMPLOT_CUSTOM_NUMERIC_TYPES="(float)(double)" will let the demo fail to link

1 participant