code: def test_domain_cpp_build_misuse_of_roles(app, status, warning):
      app.build(force_all=True)
      ws = filter_warnings(warning, "roles-targets-ok")
      assert len(ws) == 0
  
      ws = filter_warnings(warning, "roles-targets-warn")
      # the roles that should be able to generate warnings:
      allRoles = [
          "class",
          "struct",
          "union",
          "func",
          "member",
          "var",
          "type",
          "concept",
          "enum",
          "enumerator",
      ]
      ok = [  # targetType, okRoles
          ("class", ["class", "struct", "type"]),
          ("union", ["union", "type"]),
          ("func", ["func", "type"]),
          ("member", ["member", "var"]),
          ("type", ["type"]),
          ("concept", ["concept"]),
          ("enum", ["type", "enum"]),
          ("enumerator", ["enumerator"]),
          ("functionParam", ["member", "var"]),
          (
              "templateParam",
              ["class", "struct", "union", "member", "var", "type"],
          ),
      ]
      warn = []
      for targetType, roles in ok:
          txtTargetType = (
              "function" if targetType == "func" else targetType
          )
          for r in allRoles:
              if r not in roles:
                  warn.append(
                      f"WARNING: cpp:{r} targets a {txtTargetType} ("
                  )
                  if targetType == "templateParam":
                      warn.append(
                          f"WARNING: cpp:{r} targets a {txtTargetType} ("
                      )
                      warn.append(
                          f"WARNING: cpp:{r} targets a {txtTargetType} ("
                      )
      warn = sorted(warn)
      for w in ws:
          assert "targets a" in w
      ws = [w[w.index("WARNING:") :] for w in ws]
      ws = sorted(ws)
      print("Expected warnings:")
      for w in warn:
          print(w)
      print("Actual warnings:")
      for w in ws:
          print(w)
  
      for i in range(min(len(warn), len(ws))):
          assert ws[i].startswith(warn[i])
  
      assert len(ws) == len(warn)
  
imports: import itertools
  import re
  import zlib
  import pytest
  import sphinx.domains.cpp
  from sphinx import addnodes
  from sphinx.addnodes import desc, desc_content, desc_name, desc_parameter, desc_parameterlist, desc_sig_name, desc_sig_space, desc_signature, desc_signature_line, pending_xref
  from sphinx.domains.cpp import DefinitionError, DefinitionParser, NoOldIdError, Symbol, _id_prefix, _max_id
  from sphinx.ext.intersphinx import load_mappings, normalize_intersphinx_mapping
  from sphinx.testing import restructuredtext
  from sphinx.testing.util import assert_node
  from sphinx.writers.text import STDINDENT
label_desc: Use image node_id 31 for calling a global function with example usage: test_domain_cpp_build_misuse_of_roles(app, status, warning) without return types