<p>GCC 8 introduced <code>-Wsizeof-pointer-div</code> which is enabled by <code>-Wall</code> and<br>
warns for sizeof divisions that look like they would compute the size<br>
of a static array but are called on something on which this doesn't<br>
work (e.g. a pointer as LHS).  This is quite reasonable and useful, but<br>
it fails to detect the case where the computation is guarded against<br>
being called on problematic values, like our HL_N_ENTRIES() macro that<br>
accepts NULLs but won't use the sizeof computation result then.</p>
<p>Work around this by implementing HL_N_ENTRIES() macro in a way that<br>
cannot trigger such a warning yet yield the same result.</p>
<p>Example warning:</p>
<pre><code>../../src/highlighting.c: In function ‘highlighting_init_styles’:
/usr/include/glib-2.0/glib/gmacros.h:351:42: warning: division ‘sizeof (HLKeyword * {aka struct <anonymous> *}) / sizeof (HLKeyword {aka struct <anonymous>})’ does not compute the number of array elements [-Wsizeof-pointer-div]
 #define G_N_ELEMENTS(arr)  (sizeof (arr) / sizeof ((arr)[0]))
                                          ^
../../src/highlightingmappings.h:74:48: note: in expansion of macro ‘G_N_ELEMENTS’
 #define HL_N_ENTRIES(array) ((array != NULL) ? G_N_ELEMENTS(array) : 0)
                                                ^~~~~~~~~~~~
../../src/highlighting.c:966:5: note: in expansion of macro ‘HL_N_ENTRIES’
     HL_N_ENTRIES(highlighting_keywords_##LANG_NAME)); \
     ^~~~~~~~~~~~
../../src/highlighting.c:1011:3: note: in expansion of macro ‘init_styleset_case’
   init_styleset_case(CONF);
   ^~~~~~~~~~~~~~~~~~
</code></pre>
<hr>
<p>Another solution could be reporting a bug to GCC for it to detect our use case and avoid the warning then, but that might or might not be much meaningful, and won't fix the issue on currently affected GCC versions anyway.</p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/geany/geany/pull/2398'>https://github.com/geany/geany/pull/2398</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>Rewrite HL_N_ENTRIES macro to avoid a GCC8 false positive warning</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/geany/geany/pull/2398/files#diff-0">src/highlightingmappings.h</a>
    (12)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/geany/geany/pull/2398.patch'>https://github.com/geany/geany/pull/2398.patch</a></li>
  <li><a href='https://github.com/geany/geany/pull/2398.diff'>https://github.com/geany/geany/pull/2398.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany/pull/2398?email_source=notifications&email_token=AAIOWJ7ZQ7OQHDL4HOLOOXDQUAV45A5CNFSM4JOGEJQKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZZVRLA">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAIOWJ4RR2ADTYWJM57MUWDQUAV45ANCNFSM4JOGEJQA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AAIOWJZOAZX5OOVQ2ZWA4SLQUAV45A5CNFSM4JOGEJQKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZZVRLA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/geany/geany/pull/2398?email_source=notifications\u0026email_token=AAIOWJ7ZQ7OQHDL4HOLOOXDQUAV45A5CNFSM4JOGEJQKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZZVRLA",
"url": "https://github.com/geany/geany/pull/2398?email_source=notifications\u0026email_token=AAIOWJ7ZQ7OQHDL4HOLOOXDQUAV45A5CNFSM4JOGEJQKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZZVRLA",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>